sql - How to get row with default value when data not found in table -


i have table holds data date field.

ex:

|scheduled_date | --------------- |06-may-2016    | |08-may-2016    | |10-jul-2016    | 

now need count of days each month.

select case when ( select count(*)  schedule seq = '429'  , to_char((scheduled_date),'mon-yyyy')='may-2016')=0 0 else (select count(*)  schedule seq = '429'  , to_char((scheduled_date),'mon-yyyy')='may-2016') end  no_of_days, nvl(to_char((scheduled_date),'mon'),'may') month schedule seq = '429'; 

in nvl update alternate value each month before executing

when run query month of may value 2 , output .

|no_of_days |month| ------------ ----- |2          |may  | 

but month of jun need show 0, output this

|no_of_days |month| ------------ ----- |           |     | 

my desired output this

|no_of_days |month| ------------ ----- |0          |jun  | 

is there anyway achieve this?

note: have updated question not clear. sorry not able ask first time.

your query give result expect.

if want results in 1 query please do:

select to_char(scheduled_date, 'mon-yyyy'), count(*) schedule --optionally months to_char(scheduled_date, 'mon-yyyy') in (/*fill values array here*/)  , seq = '439' group to_char(scheduled_date, 'mon-yyyy'); 

if want different seq can do:

select to_char(scheduled_date, 'mon-yyyy'), seq, count(*) schedule     --optionally months     to_char(scheduled_date, 'mon-yyyy') in (/*fill values array here*/)      , seq in (/*fill values array of seqs*/)     group to_char(scheduled_date, 'mon-yyyy'), seq; 

this return counts per seq each month can process on java side.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -