sql - Can I use aggregate functions and get individual results in one query with MySQL? -


i have apartment table many columns. apartments share price , idlayout column values. however, still have different values area (shoddy workmanship).

i need to:

1) group apartments same idlayout , price, min , max area , count number of apartments in each group.

2) list individual apartments each group.

can done one query , should trying so?

what tried:

i got query first part, can't come way list apartments in result set.

select count( * ), price, rooms, max( area ) areamax, min( area ) areamin apartment group price, layout_idlayout order rooms asc, price asc  

you need use join:

select apartment.*, areamax, areamin, cnt   apartment inner join (     select       idlayout, price, max(area) areamax, min(area) areamin, count(*) cnt           apartment     group       price, layout_idlayout) ap_grp   on apartment.idlayout=ap_grp.idlayout , apartment.price=ap_grp.price 

this show apartment data, along max, min , count other apartments have same price , idlayout.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -