SQL Where COUNT() > 1

时间:2016-10-20 19:10:34

标签: sql

I have this query here:

SELECT
    concat(dateSlot, ' - ', timeSlot),
    COUNT(concat(dateSlot, ' - ', timeSlot)) + 1 AS counter
FROM myTable
Group By concat(dateSlot, ' - ', timeSlot)

This gives me the concat of dateSlot and timeSlot and the number of times it appears in the table. Now I want to add a where clause saying, I only want the rows where counter is less than 70....how would I do this?

2 个答案:

答案 0 :(得分:1)

SELECT concat(dateSlot, ' - ', timeSlot), 
       COUNT(concat(dateSlot, ' - ', timeSlot)) + 1 AS counter 
FROM myTable 
Group By concat(dateSlot, ' - ', timeSlot)
Having COUNT(concat(dateSlot, ' - ', timeSlot)) + 1 < 70

答案 1 :(得分:0)

add this clause to your query right after your AS clause

SELECT counter FROM myTable