Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Total On Groups of Data

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

I have a table with a LAB field and a CODE field. For each LAB field, how can I display the total CODES for each code type?

Example Table Data
Code:
lab   code
1     a
1     a
1     c
2     b
2     c
2     c
3     a
3     b
3     c

Example Desired Output:
Code:
LAB    CodeA   CodeB   CodeC
1      2       0       1
2      0       1       2
3      1       1       1

Thanks,

Michael42
 
Search your RDBMS documentation for CrossTab query or PivotTable.
Otherwise, another approch:
SELECT LAB, Code, Count(*) AS CountOfCode
FROM yourTable
GROUP BY LAB, Code

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top