简体   繁体   English

mySQL SELECT不止一个

[英]mySQL SELECT more than one

i have a table with colums section number like 1 , 2 , 3 etc and room number 1000, 2000, 3000, etc. Room # 2000 is being used by sections 2 and 3. 我有一个表,其中colums部分编号为1,2,3等,房间号为1000,2000,3000等。第2和第3部分正在使用#2000房间。

I want a SQL code to select the rooms that being shared by more than one section. 我想要一个SQL代码来选择由多个部分共享的房间。 Please note that I have another column called days (Sat, Sun, Mon..) and there are some rooms that are being used by same section more than once. 请注意,我有另一个名为days(Sat,Sun,Mon ..)的列,并且有一些房间被同一部分多次使用。 For example room 2000 is used Mon, Tue. 例如,房间2000用于星期一,星期二。 So using count() would not work. 所以使用count()是行不通的。

I have tried it 我试过了

SELECT 
    roomNumber
FROM

    section
having
    count(section_number) > 1

but that didn't work. 但那没用。 Please help 请帮忙

PS : I am new to mySQL PS:我是mySQL的新手

尝试

Select roomNumber from section group by roomNumber having count(roomNumber) > 1

You are very close. 你很近。 You are missing the group by clause. 您缺少group by子句。 Add that after your table declarations and before the having clause. 在表声明之后和having子句之前添加它。

select   roomNumber
from     section
group by roomNumber
having   count(section_number) > 1;

You may to adjust if you need account for null values. 如果您需要空值的帐户,您可以调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM