我在保留表(属性:名称,日期,开始,完成)上有一个SQL查询,该查询查找days属性的重复值:
SELECT day, COUNT(day) as NumberOfTimes
FROM reservation group by day HAVING (COUNT(day)>1)
ORDER BY NumberOfTimes
但是它仅返回当天,并且该天的次数在预订表中列出。我试图返回列表中列出当天列出的每个名称,但是我在查询分组时遇到了麻烦。我应该如何处理?我希望退货看起来像:
BOB MONDAY 3
JOHN MONDAY 3
STEVE MONDAY 3
ALICE WEDNESDAY 2
MARTIN WEDNESDAY 2
谢谢你的时间!
最佳答案
您不能添加名称列
SELECT
name,
day,
COUNT(day) as NumberOfTimes
FROM reservation
group by name , day
HAVING (COUNT(day) > 1)
ORDER BY NumberOfTimes
关于mysql - 从重复的列中获取所有值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14737484/