On Tue, Jul 06, 2010 at 12:06:06AM -0700, GrGsM wrote: > SELECT closedate,status, > SUM (CASE WHEN empcode = 'NT-028' THEN 1 ELSE 0 END) AS NT028, > SUM (CASE WHEN empcode = 'NT-031' THEN 1 ELSE 0 END) AS NT031, > SUM (CASE WHEN empcode = 'NT-050' THEN 1 ELSE 0 END) AS NT050, > SUM (CASE WHEN empcode = 'NT-062' THEN 1 ELSE 0 END) AS NT062 > FROM dbcleaning > WHERE status = 'Fixed' > AND empcode IN > ('NT-028', > 'NT-031', > 'NT-050', > 'NT-062') > GROUP BY closedate, status > > Now i need a column in the same result of the query which shows the > difference between the two columns . > > For Example : > the result shoud be > Closedate , status , NT028, NT031, NT050,NT062 , NT028-NT031 Just put your code above in an "inner select", something like: SELECT closedate, status, NT028-NT031 AS diff FROM ( SELECT closedate,status, SUM(CASE WHEN ... ... GROUP BY closedate, status) x; -- Sam http://samason.me.uk/ -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general