如何使用Sqlite CASE WHEN添加更多条件?

时间:2013-03-05 14:12:35

标签: android sqlite syntax case

我希望在满足案例时用更多条件评估一行。

以下是我提出的建议:

SELECT ... FROM ...
WHERE Events.CALENDAR_ID + "=?
AND case when " + Events.DTEND + ">0 
then " + Events.DTSTART + ">? end";

但是,此语句忽略了不满足该情况的行。

SELECT ... FROM ...
WHERE Events.CALENDAR_ID + "=?
case when " + Events.DTEND + ">0 
then AND " + Events.DTSTART + ">? end";

然后我想出了这个,但Sqlite告诉我这只是错误的语法。

正确的语法是什么?

1 个答案:

答案 0 :(得分:0)

正确的语法是:

SELECT ... FROM ...
WHERE "case when " + Events.DTEND + ">0 " +
" then " + Events.CALENDAR_ID + "=? AND " + Events.DTSTART + ">? " +
" else " + Events.CALENDAR_ID + "=? end"