table structure image score breakdown我有一张名为得分的高尔夫球得分表。列标题是高尔夫球手,golf_course,h1,h2,h3等等到h18。我有一个表格,根据0 =没有得分,1 =柏忌,2 =标准杆,3 =小鸟,4 =老鹰,在每列中添加得分。我想要实现的是一个声明,可以返回每行没有得分,柏忌,小鸟,小鸟或老鹰的数量。 任何帮助我都会非常感激。
答案 0 :(得分:1)
感谢Subin C Poonamgode,
你让我走上正轨。我调整了你的解决方案,使下面的代码工作jena version 3.0.0
ubuntu 15.04
intellij 14.1.4
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
whereis java: /jvm/java-8-oracle/jre/bin/java
为了获得我需要的所有其他条件,我只是将CASE 0更改为1,2,3和4。 再次感谢:-)
答案 1 :(得分:0)
SELECT golfer,
course,
(SUM(CASE WHEN scores.h1 = 0 THEN 1
WHEN scores.h2 = 0 THEN 1
WHEN scores.h3 = 0 THEN 1
WHEN scores.h4 = 0 THEN 1
WHEN scores.h5 = 0 THEN 1
WHEN scores.h6 = 0 THEN 1
WHEN scores.h7 = 0 THEN 1
WHEN scores.h8 = 0 THEN 1
WHEN scores.h9 = 0 THEN 1
WHEN scores.h10 = 0 THEN 1
WHEN scores.h11 = 0 THEN 1
WHEN scores.h12 = 0 THEN 1
WHEN scores.h13 = 0 THEN 1
WHEN scores.h14 = 0 THEN 1
WHEN scores.h15 = 0 THEN 1
WHEN scores.h16 = 0 THEN 1
WHEN scores.h17 = 0 THEN 1
WHEN scores.h18 = 0 THEN 1 ELSE 0
END)) AS total_no_score,
(SUM(CASE WHEN scores.h1 = 1 THEN 1
WHEN scores.h2 = 1 THEN 1
WHEN scores.h3 = 1 THEN 1
WHEN scores.h4 = 1 THEN 1
WHEN scores.h5 = 1 THEN 1
WHEN scores.h6 = 1 THEN 1
WHEN scores.h7 = 1 THEN 1
WHEN scores.h8 = 1 THEN 1
WHEN scores.h9 = 1 THEN 1
WHEN scores.h10 = 1 THEN 1
WHEN scores.h11 = 1 THEN 1
WHEN scores.h12 = 1 THEN 1
WHEN scores.h13 = 1 THEN 1
WHEN scores.h14 = 1 THEN 1
WHEN scores.h15 = 1 THEN 1
WHEN scores.h16 = 1 THEN 1
WHEN scores.h17 = 1 THEN 1
WHEN scores.h18 = 1 THEN 1 ELSE 0
END)) AS total_bogey,
(SUM(CASE WHEN scores.h1 = 2 THEN 1
WHEN scores.h2 = 2 THEN 1
WHEN scores.h3 = 2 THEN 1
WHEN scores.h4 = 2 THEN 1
WHEN scores.h5 = 2 THEN 1
WHEN scores.h6 = 2 THEN 1
WHEN scores.h7 = 2 THEN 1
WHEN scores.h8 = 2 THEN 1
WHEN scores.h9 = 2 THEN 1
WHEN scores.h10 = 2 THEN 1
WHEN scores.h11 = 2 THEN 1
WHEN scores.h12 = 2 THEN 1
WHEN scores.h13 = 2 THEN 1
WHEN scores.h14 = 2 THEN 1
WHEN scores.h15 = 2 THEN 1
WHEN scores.h16 = 2 THEN 1
WHEN scores.h17 = 2 THEN 1
WHEN scores.h18 = 2 THEN 1 ELSE 0
END)) AS total_par,
(SUM(CASE WHEN scores.h1 = 3 THEN 1
WHEN scores.h2 = 3 THEN 1
WHEN scores.h3 = 3 THEN 1
WHEN scores.h4 = 3 THEN 1
WHEN scores.h5 = 3 THEN 1
WHEN scores.h6 = 3 THEN 1
WHEN scores.h7 = 3 THEN 1
WHEN scores.h8 = 3 THEN 1
WHEN scores.h9 = 3 THEN 1
WHEN scores.h10 = 3 THEN 1
WHEN scores.h11 = 3 THEN 1
WHEN scores.h12 = 3 THEN 1
WHEN scores.h13 = 3 THEN 1
WHEN scores.h14 = 3 THEN 1
WHEN scores.h15 = 3 THEN 1
WHEN scores.h16 = 3 THEN 1
WHEN scores.h17 = 3 THEN 1
WHEN scores.h18 = 3 THEN 1 ELSE 0
END)) AS total_birdie,
(SUM(CASE WHEN scores.h1 = 4 THEN 1
WHEN scores.h2 = 4 THEN 1
WHEN scores.h3 = 4 THEN 1
WHEN scores.h4 = 4 THEN 1
WHEN scores.h5 = 4 THEN 1
WHEN scores.h6 = 4 THEN 1
WHEN scores.h7 = 4 THEN 1
WHEN scores.h8 = 4 THEN 1
WHEN scores.h9 = 4 THEN 1
WHEN scores.h10 = 4 THEN 1
WHEN scores.h11 = 4 THEN 1
WHEN scores.h12 = 4 THEN 1
WHEN scores.h13 = 4 THEN 1
WHEN scores.h14 = 4 THEN 1
WHEN scores.h15 = 4 THEN 1
WHEN scores.h16 = 4 THEN 1
WHEN scores.h17 = 4 THEN 1
WHEN scores.h18 = 4 THEN 1 ELSE 0
END)) AS total_eagle,
FROM scores
这可能有效。
希望这会有所帮助。