0

请帮助将以下 MySQL 查询更改为 SQLite

SELECT 
    DISTINCT t.arabic_term AS t__1,
    SUBSTR(t.definition, 1, 60) AS Definition,
    Sum(if(t3.is_main="y", 1 ,0)) AS t3__5
FROM term t 
INNER JOIN term_disease t2 ON (t2.disease_id = t.term_id) 
INNER JOIN term_disease_symptom t3 ON (t3.disease_id = t2.disease_id)
WHERE (t3.symptom_id in ( 45378 , 45351, 5546 ) AND t2.gender != 1  AND t2.active = 1 )
GROUP BY t3.disease_id
ORDER BY t3__5  desc;
4

2 回答 2

1

SQLite 没有IF函数,但布尔表达式被定义为具有值 1 或 0。因此,特定的表达式将是:

SUM(t3.is_main = 'y') AS t3__5

其他任何东西都是标准 SQL。

于 2012-09-27T08:32:16.440 回答
1

以下

Sum(if(t3.is_main="y", 1 ,0)) AS t3__5 

应该替换为

SUM(CASE t3.is_main WHEN 'y' THEN 1 ELSE 0 END) AS t3__5 
于 2012-09-27T08:55:37.317 回答