这里我想把计数当作表中相同的值,假设我的表中的例子Accomodation
是两次,所以,住宿计数应该是2,剩余计数是1
getting_fecilities
fid eventId fecilityName
1 5 Accomodation
2 5 Breakfast
3 5 Lunch
4 5 Dinner
5 6 Food(VEG)
6 5 Parking
7 5 Accomodation
MYSQL
SELECT `fecilityName`,COUNT(*) AS count FROM getting_fecilities WHERE eventId=5 group by `fecilityName`
我的结果
fecilityName count
Accomdation 1
Accomdation 1
Breakfast 1
Dinner 1
Lunch 1
Parking 1
我的预期结果
fecilityName count
Accomdation 2
Breakfast 1
Dinner 1
Lunch 1
Parking 1
答案 0 :(得分:1)
您的查询正在给出预期结果。 请在以下链接中查看:
答案 1 :(得分:0)
SELECT `fecilityName`, COUNT(fecilityName) AS count
FROM getting_fecilities WHERE eventId = 5
group by `fecilityName`;