Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL sentence
Noriepa,
You can use a group by to get a count(*) for each existing code per city
UT1 > select * from citycode;
C CO
- --
A XX
B SS
A ZZ
C YY
D XX
B SS
B ZZ
7 rows selected.
UT1 > select city, code, count(*) from citycode group by city, code;
C CO COUNT(*)
--- ----- -----
A XX 1 A ZZ 1 B SS 2 B ZZ 1 C YY 1 D XX 1
6 rows selected.
You can then pivot this data (by feeding this query result into a join with the pivot table). You can find information on pivot tables in the newsgroup archives and/or at the asktom.oracle.com website.
HTH -- Mark D Powell -- Received on Thu Jul 21 2005 - 09:04:02 CDT
![]() |
![]() |