Skip to content
Advertisement

Using SUM and CASE in Oracle SQL

I framed a query to get the counts grouped by a date column from 2 tables.

I wanted to get the results from both tables, hence I used UNION. And since I wanted the hourly breakup of counts I grouped by TO_CHAR(CREATION_DATE, 'DD/Mon/YY HH')

The output is something like this:

As you can see, I want the output counts to be summed up by the hour from both the tables and give a result like this:

I can do this excel, but it’s not practical. I am thinking of CASE statements in Oracle but never really implemented it.

Database: Oracle Editor: Toad for Oracle

Advertisement

Answer

Use your current query as data source for the final result:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement