2014-11-06 160 views
0

我在分組我的數據掙扎,現在我有這個GROUP BY子句中的MySQL

enter image description here

如果我組通過名稱(第1列),這個結果我的數據將成爲

enter image description here

什麼,我這是什麼

enter image description here

正如你所看到的,我想將我的專欄1分組,其中name(column2)是相同的任何想法如何實現。

PS:我查詢這個結果對我的6張桌子,這裏是我的查詢

select a.name, b.name, d.price, e.id from tbl1 a, tbl2 b, tbl3 c, 
tbl4 d, tbl5 e, tbl6 f 
where a.id=c.patron_id and b.id=c.cinema_id and d.movies_schedule_list_id=e.id 
and e.movies_schedule_id=f.id and f.cinema_id=b.id and f.movie_date = '2014/10/31' 
order by b.name; 

我試圖把

group by a.name having b.name= ?? 

但我不知道我在哪裏可以等於在B .name.請幫助我,請提前致謝

回答

3

只是將兩個字段按照標準結合起來作爲您的羣組

group by a.name, b.name 
1

在where子句的末尾,放入 GROUP BY a.name,b.name ORDER BY b.name;