sql - Query to display zero it the sum of entries of the particular month is 0 -


i'm preaty weak in sqlite queries .

i have set of entries in sqlite database. want find sum, grouped in months.

select sum(quantity) quantity, strftime('%m', created_on) month orderitembit  (strftime('%y%m',created_on) between '201210' , '201303') group month 

the problem if there no entry particular month, want entry should display count zero, not showing anything.

ex. guess there no entry month of jan above query. should display quantity 0.

can solve problem!!! in advance

one way this, create temp table contain list of month names, join table. or can create on fly; like:

select   m.monthname,   ifnull(sum(o.quantity), 0) quantity  (   select 'january' monthname   union   select 'march'   union   ... ) months left join orderitembit o on o.month = strftime('%m', o.created_on) (strftime('%y%m', o.created_on) between '201210' , '201303') group m.monthname; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -