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