March 30, 2009 at 11:30 am
Good Afternoon,
I have, what I am guessing, is a simple question. I am using the following query:
SELECT site_area.site_area_sc, site.site_sc, bldng.bldng_sc, bldng_room.bldng_room_sc, item.item_id
FROM bldng INNER JOIN
bldng_room ON bldng.bldng_id = bldng_room.bldng_id INNER JOIN
item ON bldng_room.bldng_room_id = item.bldng_room_id INNER JOIN
site ON bldng.site_id = site.site_id INNER JOIN
site_area ON site.site_area_id = site_area.site_area_id
ORDER BY site_area.site_area_sc, site.site_sc, bldng.bldng_sc, bldng_room.bldng_room_sc
This query give me the results I expect but...I need to add a count to this to tell me how many item_ids I have in each bldng.
Any help is greatly appeciated.
Di-
March 30, 2009 at 1:14 pm
Hi
You can select either the item_id or count it. If you need the item_id. If you don't need the item_id you can GROUP BY the other columns and add a COUNT(*).
The only way to get both, the item_id and the count of them (in each row), would be a sub-query or a CTE.
Greets
Flo
March 30, 2009 at 3:06 pm
Thank you for the quick response. I used the Group By and it works like a charm.
Di-
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply