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;
I WANT TO KNOW WHY FUN LIKE SUM IS NOT ALLOWED IN GROUP BY
Moderators: Kalicharan, Moderator Group
-
- Moderator
- Posts: 1625
- Joined: Sat Aug 09, 2008 9:02 am
- Location: Mumbai, India
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.
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
Anuj
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.
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.
Following query working... please check.
Code: Select all
SELECT YEAR(HIREDATE), COUNT(*)
FROM EMP
GROUP BY YEAR(HIREDATE)
Natarajan
Chennai
Chennai
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page