GROUP BY Clause in Oracle
 Hello Friends, 
                     Today I am going to tell you some interesting facts about oracle queries. SQL and Oracle Queries are seems to be same. Query which run fine on Mysql are expected to give same results on oracle , But some constraints are different for Oracle. I am explaining few of them :
GROUP BY clause :  
                                   In Oracle all the fields which are selected , should be in Group By clause  
Take an example to understand this :
QUERY :    Select  st_name, marks, semester from student group by st_name;
In MySql   : query runs fine and give the resultset . 
Oracle :    Select  st_name, marks, semester from student group by st_name;
Query Result : ORA-00979: *not a group by expression 
Solution :   Select  st_name, marks, semester from student group by st_name, marks, semesters;
 But Group By clause does not contains group function arguments such as SUM, MIN, MAX or COUNT.
Example :  Select  st_name, sum(marks), semester from student group by st_name, semesters;
Example2 : 
                  select department, count(*) as no_of_result from employee where salary >25000 group  by department;
 
No comments:
Post a Comment