GROUP BY:
---------
select dcode, sum(salary) from ex_details group by dcode;
Any ungrouped column(like dcode above)should be part of group by clause.
/* -- Its incorrect, because where clause connot have group function like min(). Where clause always performs only on row.
where restricts row.
Select dcode, sum(salary) from ex_details
where min(salary) > 3000
group by dcode;
*/
Select dcode, sum(salary) from ex_details
Having min(salary) > 3000
group by dcode;
or
Select dcode, sum(salary) from ex_details
group by dcode Having min(salary) > 3000;
In Group By clause you cannot specify functions like min(),max(). Group By always looks for column name.
select count(distinct salary) from ex_emp;
Monday, October 11, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment