任何人都可以帮我解释为什么下面更改的行返回0而不是请求的11或12? 我正在使用MySQL,否则这个查询运行正确...我试图在上述字段中捕获0和null之间的区别。
SELECT SUM(CASE WHEN pr.heatEventID=1 THEN pr.points+1 ELSE '-' END) AS `100m`
, SUM(CASE WHEN pr.heatEventID=25 THEN pr.points+1 ELSE '-' END) AS `200m`
, SUM(CASE WHEN pr.heatEventID=37 THEN pr.points+1 ELSE '-' END) AS `400m`
, SUM(CASE WHEN pr.heatEventID=49 THEN pr.points+1 ELSE '-' END) AS `800m`
, SUM(CASE WHEN pr.heatEventID=61 THEN pr.points+1 ELSE '-' END) AS `1500m`
, SUM(CASE WHEN pr.heatEventID=67 THEN (CASE WHEN pr.points IS NULL THEN 11 ELSE 12 END) ELSE '' END) AS `3000m`
, SUM(CASE WHEN pr.heatEventID=69 THEN pr.points+1 ELSE '-' END) AS `Javelin`
, SUM(CASE WHEN pr.heatEventID=81 THEN pr.points+1 ELSE '-' END) AS `Shot Put`
, SUM(CASE WHEN pr.heatEventID=93 THEN pr.points+1 ELSE '-' END) AS `Discus`
, SUM(CASE WHEN pr.heatEventID=105 THEN pr.points+1 ELSE '-' END) AS `High Jump`
, SUM(CASE WHEN pr.heatEventID=117 THEN pr.points+1 ELSE '-' END) AS `Long Jump`
FROM participation_reports AS pr
JOIN event_data on event_data.eventID=pr.heatEventID
WHERE pr.competitorID=32
我得到了结果: 8 8 10 8 9 0 6 7 8 1 7
谢谢:)
**编辑是将SQL更正为右ctrl + V:P
答案 0 :(得分:0)
解决方案 - 将是SUM():)感谢Matt Gibson(微妙地)指出...当然SUM(' - ')将为0 - 因此0 ....如果我从CASE周围删除了SUM()然后我得到了我想要的东西:)
谢谢!