SQL subquery with COUNT help

前端 未结 4 1729
挽巷
挽巷 2021-02-01 13:41

I have an SQL statement that works

SELECT * FROM eventsTable WHERE columnName=\'Business\'

I want to add this as a subquery...

         


        
4条回答
  •  無奈伤痛
    2021-02-01 14:00

    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'
    

提交回复
热议问题