I have an SQL statement that works
SELECT * FROM eventsTable WHERE columnName='Business'
I want to add this as a subquery...
COUNT(Business) AS row_count
How do I do this?
This is probably the easiest way, not the prettiest though:
SELECT *,
(SELECT Count(*) FROM eventsTable WHERE columnName = 'Business') as RowCount
FROM eventsTable
WHERE columnName = 'Business'
This will also work without having to use a group by
SELECT *, COUNT(*) OVER () as RowCount
FROM eventsTables
WHERE columnName = 'Business'
OVER is not supported by the SQL standard, and it won't be available across all the RDBMS (For example, MySQL doesn't support it).Do you want to get the number of rows?
SELECT columnName, COUNT(*) AS row_count
FROM eventsTable
WHERE columnName = 'Business'
GROUP BY columnName
where clause in group by. Use Havingwhere clause with group by. You would need to use having if you wanted to filter on the result of an aggregate when using group by.