Link to home
Start Free TrialLog in
Avatar of csePixelated
csePixelatedFlag for United States of America

asked on

sql results as single table

I am trying to get a simple table of results showing the number of times we have entries meeting the criteria below, when i run the below i get each result in a separate result payne how do i get the count in a simple table?
SELECT count (*) 
FROM [History0218].[dbo].[SignalHistory]
WHERE PortNum = 3 and LineNum = 1
SELECT count (*) 
FROM [History0218].[dbo].[SignalHistory]
WHERE PortNum = 3 and LineNum = 2
SELECT count (*) 
FROM [History0218].[dbo].[SignalHistory]
WHERE PortNum = 3 and LineNum = 3

Open in new window

i need to check all the way to LineNum = 20
Avatar of Bill Prew
Bill Prew

How do you want the output to look?


»bp
Avatar of csePixelated

ASKER

A single column named 'Call Count' numbered with rows 1-20.
Okay, give this a try:

SELECT LineNum, COUNT(*) AS [Call Count] FROM [History0218].[dbo].[SignalHistory] WHERE PortNum = 3 and LineNum = 1
UNION
SELECT LineNum, COUNT(*) AS [Call Count] FROM [History0218].[dbo].[SignalHistory] WHERE PortNum = 3 and LineNum = 2
UNION
SELECT LineNum, COUNT(*) AS [Call Count] FROM [History0218].[dbo].[SignalHistory] WHERE PortNum = 3 and LineNum = 3

Open in new window


»bp
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>A single column named 'Call Count' numbered with rows 1-20.
Not really certain what the 'rows 1-20' means but would something like this work?
SELECT LineNum, COUNT(LineNum)  as the_count
FROM [History0218].[dbo].[SignalHistory]
GROUP BY LineNum
WHERE PortNum = 3 AND LineNum >= 1 AND LineNum <= 20
ORDER BY LineNum

Open in new window

(post code edit)  Jinx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial