csePixelated
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
i need to check all the way to LineNum = 20
ASKER
A single column named 'Call Count' numbered with rows 1-20.
Okay, give this a try:
»bp
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
»bp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>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?
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
(post code edit) Jinx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
»bp