#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11

    Need help with max in group by


    I know we have to use group by, having and max in this but still not able to figure out
    Please help

    Write a SQL to query employee table where employees salary between 1000 to 2000 as catogory A and 2000 to 4000 as category B and etc...
    and choose the maximum salary in each category
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,244
    Rep Power
    4279
    sorry, we don't do homework assignments on this site

    show us your best effort, and we'll critique it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11
    This is what I came up with so far
    SELECT *, 'A' from employee where salary between 1000 and 2000
    union
    SELECT *, 'B' from employee where salary between 2000and 3000
    union
    SELECT *, 'C' from employee where salary between 3000 and 4000
    For max
    select MAX(salary) from employee
    where salary between 1 and 900000.00
    union
    select MAX(salary) from employee
    where salary between 900000.00 and 1000000.00
    Is it possible to combine the results?
    Last edited by superprogrammer; September 11th, 2012 at 12:40 PM.
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,244
    Rep Power
    4279
    Originally Posted by superprogrammer
    This is what I came up with so far
    what happened when you tested it?

    Originally Posted by superprogrammer
    Is it possible to combine the results?
    only if you like complex, shoe-horned solutions
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo