Quote:
> Hello,
> I have a sql question.
> SELECT C1,COUNT(*) FROM T1
> WHERE C2 = 5
> AND GROUP BY C1
> SELECT C1,COUNT(*) FROM T1
> WHERE C2 <> 5
> AND GROUP BY C1
> These two queries should be in one SQL like Select c1,count(*) as
> c2eq5,count(*) as c2ne5 from t1
> group by c1
> Is is possible in DB2 V5 on os390
Yes. YMMV
SELECT C1, SUM(EQ5) AS C2EQ5, SUM(NE5) AS C2NE5
FROM (SELECT C1, COUNT(*) AS EQ5, 0 AS NE5
FROM T1
WHERE C2 = 5
UNION ALL
SELECT C1, 0, COUNT(*)
FROM T1
WHERE C2 ^= 5)
GROUP BY C1
You'll most likely have to use the appropriate scalar function on
the COUNT(*)'s and zero literals to fit the expected domain of your
count; in other words coerce the type.
Glenn