0

Please help to change the below MySQL query to 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;

2 Answers 2

1

Below

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

sould be replaced with

SUM(CASE t3.is_main WHEN 'y' THEN 1 ELSE 0 END) AS t3__5 
Sign up to request clarification or add additional context in comments.

Comments

1

SQLite does not have an IF function, but boolean expression are defined as having the values 1 or 0. So that particular expression would be:

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

Anything else is standard SQL.

1 Comment

In SQLite, the expression t3.is_main = 'y' already is 0 or 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.