If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > why column function can't be in where-clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-05, 21:09
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
why column function can't be in where-clause

How to get all the PERSON.NAME that has total workload <= 100? Thx
Why can't let column function in where-clause? Thx

DDL:
CREATE TABLE PERSON
(NAME CHAR(8), DEPT_ID CHAR(18), WORKLOAD INT)

COMMIT;

INSERT INTO PERSON VALUES('NIDM','ENGINEERING', 50);
INSERT INTO PERSON VALUES('NIDM','IT', 50);


This is OK:
SELECT NAME, SUM(WORKLOAD) FROM PERSON
GROUP BY NAME;

But this, got -120:
SELECT NAME FROM PERSON
WHERE SUM(WORKLOAD) <= 100
GROUP BY NAME;
Reply With Quote
  #2 (permalink)  
Old 01-20-05, 21:15
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Use having:

SELECT NAME FROM PERSON
GROUP BY NAME
HAVING SUM(WORKLOAD) <= 100
Reply With Quote
  #3 (permalink)  
Old 01-20-05, 21:21
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Thanks a lot

Quote:
Originally Posted by chuzhoi
Use having:

SELECT NAME FROM PERSON
GROUP BY NAME
HAVING SUM(WORKLOAD) <= 100
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On