Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Lite: I want to add +1 everytime a criteria is met

So i want to check if a criteria is met and then add +1 everytime.

i tried it like this

SELECT Track,
 CASE 
 WHEN Duration like '%05:%' then metrics_count + 1
 WHEN Danceable = 'not very danceable' then metrics_count + 1
 WHEN Energy = 'high energy' then metrics_count + 1
 WHEN Emotion = 'moody' THEN metrics_count + 1
 WHEN  "Key" = 'C#' THEN metrics_count + 1
End as metrics_count
FROM
 table

but i just get nulls or 1 so it doest add up it restarts everytime i think.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Looks you need next

SELECT Track,
    (case when Duration like '%05:%' then 1 else 0 end) +
    (case when Danceable = 'not very danceable' then 1 else 0 end) +
    (case when Energy = 'high energy' then 1 else 0 end) +
    -- other cases
    (case when Emotion = 'moody' then 1 else 0 end) as metrics_count
FROM
 table

SQLite online test

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading