Enhance current SQLite query -



Enhance current SQLite query -

i inherited old sqlite database should not alter (this requirement). there many tables, focus on 2 of them:

songs ---------- song_id (primary autoincrement) group_id (external) title audio_file_path waspurchased (boolean, 0/1) groups ---------- group_id (primary autoincrement, related songs group_id) group_name

at moment, application needs perform query:

select song_id,title,audio_file_path,waspurchased,g.group_name groupname, g.group_id groupid songs s bring together groups g on s.group_id=g.group_id order groupname desc

is there way, same query, extract how many distinct g.group_id have waspurchased=0?

any help appreciated.

select song_id,title,audio_file_path,waspurchased, g.group_name groupname, g.group_id groupid, sum (select distinct g.group_id yourtables/join waspurchased = 0) nb songs s bring together groups g on s.group_id=g.group_id order groupname desc

not sure if it's best way(never tried select in sum but...), think help you.

sqlite

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -