How can I make two condition in having clause

前端 未结 4 1713
傲寒
傲寒 2021-01-02 07:47

I have a table similar to:

domain      |   file      | Number 
------------------------------------     
aaa.com     | aaa.com_1   | 111
bbb.com     | bbb.co         


        
4条回答
  •  没有蜡笔的小新
    2021-01-02 08:00

    You cannot have the file name in the SELECT statement if it is not also in the GROUP BY. You have to get your GROUP BY result than JOIN back to the original and add the filter logic like so:

    SELECT *
    FROM
    (
     select count(domain) as 'sum_domains', Number
     from table 
     group by Number
     having
     count(Number) >1
    ) result
    join table t on result.Number = t.Number
    WHERE file like '%\_1'
    

提交回复
热议问题