Monday, April 13, 2015

Add two counts in SQL

use COALESCE to default to zero:
SELECT COALESCE(MAR1.GENERATED,0)

SELECT  SUM(s.TOTAL_DOCS) totalHours
FROM (
        ( SELECT count(*) as TOTAL_DOCS
  FROM  x WHERE  ..
        )
          UNION ALL

(SELECT count(*) as TOTAL_DOCS FROM  x
          WHERE ...
          )
        ) s

No comments:

Post a Comment