select users have more than one distinct records in mysql

后端 未结 3 2079
眼角桃花
眼角桃花 2020-12-15 21:11

For a table that holds the records of user\'s webpages visiting behavior, how can I select users that visit more than one webpages.

The structure of this tables is:<

3条回答
  •  萌比男神i
    2020-12-15 22:02

    Try this:

    SELECT userId, COUNT(DISTINCT webpageId) AS count FROM visits GROUP BY userId
    having COUNT(DISTINCT webpageId) > 1
    

    More: HAVING

提交回复
热议问题