如何在Android上的SQLite中使用CASE WHEN汇总两个字段

时间:2016-04-03 19:39:14

标签: android sqlite

我想显示字段尝试的总和以及连接在一起的点的总和,但我只得到字段尝试的总和。

SELECT
ContactName,
SUM(CASE WHEN event = 'Event1' THEN tries || '/' || points END) AS "E1",
SUM(CASE WHEN event = 'Event2' THEN tries || '/' || points END) AS "E2",
SUM(CASE WHEN event = 'Event3' THEN tries || '/' || points END) AS "E3",

FROM names
WHERE
period = 2
GROUP BY
ContactName

1 个答案:

答案 0 :(得分:1)

我通过划分两个总和

来做到以下几点
SUM(CASE WHEN event = 'Event1' THEN tries END) || "/" || SUM(CASE WHEN event = 'Event1' THEN points END) AS "E1"