I WANT TO KNOW WHY FUN LIKE SUM IS NOT ALLOWED IN GROUP BY

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
gvs
Member
Posts: 2
Joined: Sun Dec 20, 2009 4:38 pm

I WANT TO KNOW WHY FUN LIKE SUM IS NOT ALLOWED IN GROUP BY

Post by gvs » Sun Dec 20, 2009 4:51 pm

HELLO ,IAM NEW TO DB2 ,CAN ANY ONE GIVE ME EQUALENT QUERY FOR BELOW QUERIES IN DB2
SELECT YEAR(HIREDATE) RECUITEDYEAR
FROM EMPLOYEE
GROUP BY YEAR(HIREDATE);
IT IS GIVING ERROR.I I WANT TO KNOW DB2 NOT ALLOWING FUNCTIONS
IN GROUP BY CLAUSE. AND ALSO


SELECT SALARY,(SELECT MAX(SALARY) FROM EMPLOYEE;

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Mon Dec 21, 2009 4:12 pm

TURN OFF your CAPS.

What do you ask? It's not clear from your description what you are trying to do? Do yo want to know," can functions be used with GROUP BY clause in DB2?" If yes may be this link can help you a bit; Else do a better job in explaining your query.
Regards,
Anuj

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Mon Dec 21, 2009 6:12 pm

Anuj provided very good source to learn about GROUP BY clause in DB2.
Please go thru that page.

As per what i understand from your first query.. you want to display the YEAR part of HIREDATE, without duplicates... Is my understanding is correct?
Natarajan
Chennai

gvs
Member
Posts: 2
Joined: Sun Dec 20, 2009 4:38 pm

Post by gvs » Mon Dec 21, 2009 7:25 pm

Thanks for the reply.In my first query i want to display the years in which recruitment had taken place.As you suggested i can use distinct to eliminate duplicate.But if we want to
count the number of recruitments happened in the year how to do it in db2.In oracle
i can write query as
select to_char(hiredate,'yyyy'),count(*)
from emp
group by to_char(hiredate,'yyyy');

In my two query my desired output is something like
salary max(salary)
1000 30000
2000 30000
2541 30000
for that i need query in db2,
in oracle select salary,(select max(salary) from employee)
from employee;
but in db2 it is giving error like "max" is invalid.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Wed Dec 23, 2009 3:04 pm

Following query working... please check.

Code: Select all

SELECT YEAR(HIREDATE), COUNT(*)
FROM EMP
GROUP BY YEAR(HIREDATE)
Natarajan
Chennai

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others