0
與像數據開始聚集條款如下:MySQL查詢超過幾個條件
clubType desiredShape lineDirection
---------------------------------------
driver straight left
driver draw straight
iron straight right
wedge straight straight
iron fade right
wedge straight straight
iron fade left
iron draw straight
我想編寫一個查詢,可以返回:
- 計數desiredShape =「畫」
- count desiredShape =「straight」
- count desiredShape =「fade」
- count lineDirection =「left」
- 數將lineDirection = 「直」
- 數將lineDirection = 「右」
每各clubType
所以,我試圖做這樣的事情:
SELECT
clubType,
(SELECT count(*) FROM shots WHERE desiredShape = "fade") as count_DesiredFade,
(SELECT count(*) FROM shots WHERE desiredShape = "draw") as count_DesiredDraw,
(SELECT count(*) FROM shots WHERE desiredShape = "straight") as count_DesiredStraight
...
FROM shots
GROUP BY clubType
但它不是對。不知道如何迭代clubtype並彙總其他計數。
我想用這樣的事情結束了:
clubType desDraw desFade desStraight lineLeft lineRight lineRight
-----------------------------------------------------------------------------
driver 3 2 4 3 2 1
iron 4 1 2 4 2 1
wedge 1 3 2 1 0 2
釘它第一次嘗試。好工作 – Kristian