View previous topic :: View next topic |
Author |
Message |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Wed Nov 21, 2007 6:19 am Post subject: collect ,grouping and counting columns from a table |
|
|
hi all,
Code: |
A B
--------- ---------
220126 20180
20180 220126
220126 20180
20180 220126
20180 220126
|
I need a result like this:
where "220126" is the subject of both two columns of the table while "2" is the counter of first column and 3 of the second one.
how can i do?
thanks in advance |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Nov 21, 2007 9:31 am Post subject: |
|
|
This will get you started in the right direction.
Code: |
SELECT COL_NM,SUM(COL1_CNT),SUM(COL2_CNT)
FROM (
SELECT COLA AS COL_NM,COUNT(*) AS COL1_CNT,0 AS COL2_CNT
FROM SESSION.JS_TBL
GROUP BY COLA
UNION ALL
SELECT COLB AS COL_NM,0 COL1_CNT,COUNT(*) AS COL2_CNT
FROM SESSION.JS_TBL
GROUP BY COLB
) AS TEMP_TBL
GROUP BY COL_NM;
|
|
|
Back to top |
|
 |
enge Beginner
Joined: 12 Oct 2004 Posts: 78 Topics: 39
|
Posted: Wed Nov 21, 2007 9:40 am Post subject: |
|
|
it really work!
thanks a lot |
|
Back to top |
|
 |
|
|