sql - Add a default value in group by select in case a specific value is not present -


i have following table:

code | value | req_date 

and following query:

select code, sum(value) sums, req_date table                 group code,req_date 

normally codes "0" , "30" should present, anyway i'd make that, if not present, following default records

"0" | 0 | <date> "30"| 0 | <date> 

appear. possible?

if after default value 0 , 30, unioning table additional rows default data , grouping whole lot should work:

select     code     ,sum(value) sums     ,req_date (      select       code       ,value       ,req_date      table      union      select       '30' code       ,0 value       ,sysdate req_date --default date here      union      select       '0' code       ,0 value       ,sysdate req_date --default date here ) uniontable  group code ,req_date 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -