3
Group By Having with Left Outer Join CIS430/530 Sunnie Chung Select D.Dnumber, E.dno, E.salary From Department D Left Outer Join Employee E ON D.Dnumber = E.dno; /*Count(*) count a tuple of the join result*/ Select D.dnumber, Count(*), SUM(E.salary) From Department D Left Outer Join Employee E ON D.Dnumber = E.dno Group By D.dnumber; /* NULL as Group */ Select E.dno, Count(E.dno), SUM(E.salary) From Department D Left Outer Join Employee E ON D.Dnumber = E.dno Group By E.dno;

Group By Having with Left Outer Joincis.csuohio.edu/~sschung/cis430/ExampleGroupByLeftOuterJoin.pdf · SQLQuery3.sql- X (55)) D. Dnumber, E dno, E. salary Left Outer Join Employee

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Group By Having with Left Outer Joincis.csuohio.edu/~sschung/cis430/ExampleGroupByLeftOuterJoin.pdf · SQLQuery3.sql- X (55)) D. Dnumber, E dno, E. salary Left Outer Join Employee

Group By Having with Left Outer Join

CIS430/530

Sunnie Chung

Select D.Dnumber, E.dno, E.salary From Department D Left Outer Join Employee E

ON D.Dnumber = E.dno;

/*Count(*) count a tuple of the join result*/

Select D.dnumber, Count(*), SUM(E.salary)

From Department D Left Outer Join Employee E

ON D.Dnumber = E.dno Group By D.dnumber;

/* NULL as Group */ Select E.dno, Count(E.dno), SUM(E.salary)

From Department D Left Outer Join Employee E

ON D.Dnumber = E.dno Group By E.dno;

Page 2: Group By Having with Left Outer Joincis.csuohio.edu/~sschung/cis430/ExampleGroupByLeftOuterJoin.pdf · SQLQuery3.sql- X (55)) D. Dnumber, E dno, E. salary Left Outer Join Employee

/*COUNT counts Duplicates*/

Select Count(E.dno) from employee E;

/*To COUNT Unique Values Only*/ Select Count(Distinct E.dno)

from employee E;

/*COUNT Does NOT count NULL values*/ Select Count(E.superssn)

from employee E;

Page 3: Group By Having with Left Outer Joincis.csuohio.edu/~sschung/cis430/ExampleGroupByLeftOuterJoin.pdf · SQLQuery3.sql- X (55)) D. Dnumber, E dno, E. salary Left Outer Join Employee

Select D.dnumber, Count(E.dno), Sum(E.Salary)

From Department D Left Outer Join Employee E ON D.Dnumber = E.dno

Group By D.dnumber;

Select D.dnumber, Count(E.dno), Sum(E.Salary)

From Department D Left Outer Join Employee E

ON D.Dnumber = E.dno Group By D.dnumber

Having COUNT(E.dno) > 2;