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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -