?
Solved

SQL Query help

Posted on 2007-10-09
2
Medium Priority
?
221 Views
Last Modified: 2010-03-19
hello there,

i have this query which i get correct data.now i want to know can i change this query to iterate co_id from 1 to the last co_id and return all the values.rather me entering co_id for each of the co_id in the table.

Select a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  and CO_ID = 2
                  group by a.STATE_ID, a.NAME
                  order by STATE_ID
0
Comment
Question by:zolf
2 Comments
 
LVL 14

Expert Comment

by:Jai S
ID: 20039220
just remove teh CO_ID checking from your query

Select a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  group by a.STATE_ID, a.NAME
                  order by STATE_ID
0
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 20039231
try

Select CO_ID , a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  group by CO_ID , a.STATE_ID, a.NAME
                  order by STATE_ID
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question