Reputation: 9235
I have the following query in SQL:
SELECT TOP 1000 [Date]
,[APDERM]
,[IN HOUSE]
,[RAD EMR ORDERS]
,[EMR ORDERS]
FROM [database].[dbo].[MYTABLE]
Which produces this:
How can I write a query which will add each column and insert a new row under the [MYTABLE]
Something like this:
Upvotes: 0
Views: 79
Reputation: 26
you can try this to do it in a single statement:
SELECT TOP 1000 [Date]
,SUM([APDERM]) AS [APDERM]
,SUM([IN HOUSE]) AS [IN HOUSE]
,SUM([RAD EMR ORDERS]) AS [RAD EMR ORDERS]
,SUM([EMR ORDERS]) AS [EMR ORDERS]
FROM [database].[dbo].[MYTABLE]
GROUP BY [Date]
WITH ROLLUP
Upvotes: 1
Reputation: 3290
This doesn't do EXACTLY what you asked for, but this should be close enough:
SELECT TOP 1000 [Date]
,[APDERM]
,[IN HOUSE]
,[RAD EMR ORDERS]
,[EMR ORDERS]
FROM [database].[dbo].[MYTABLE]
COMPUTE SUM(APDERM), SUM([In House]), SUM([RAD EMR ORDERS]), SUM([EMR ORDERS])
This will post the sums of those columns as a second dataset, rather than appending it to the end of that one.
Upvotes: 1
Reputation: 3437
Use UNION
operator:
SELECT [Date]
,[APDERM]
,[IN HOUSE]
,[RAD EMR ORDERS]
,[EMR ORDERS]
FROM [database].[dbo].[MYTABLE]
UNION
SELECT [Date]
, SUM([APDERM])
, SUM([IN HOUSE])
, SUM([RAD EMR ORDERS])
, SUM([EMR ORDERS](
FROM [database].[dbo].[MYTABLE]
Upvotes: 1