返回布尔值为 0 的列的名称
我想查询下表以返回 SessionId 和 Roomx 的交集为 0 的列的标题。Room 的类型是 TINYINT - 在 mysql 中表示 BOOLEAN
下面是表格:
SessionId Room1 Room2 Room3
1 0 1 0
2 1 0 1
对于上面的表格,例如SessionId 1 ,查询应返回 Room1 和 Room3 非常感谢您的帮助。 谢谢。
I want to query the table below as to return the titles of the column where the intersection of SessionId and Roomx is 0.The type of the Room is TINYINT - which in mysql represents BOOLEAN
Below is the table:
SessionId Room1 Room2 Room3
1 0 1 0
2 1 0 1
For the above table for example for SessionId 1 , query should return Room1 and Room3
Help will be much appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,它就像一张需要重新设计的桌子。从列名来看,您应该处理的“对象”(行)是“事件”:事件发生在一个房间中、一个部分的期间。通过这种设置,您的表格将如下所示:
现在仍然没有查询可以为您提供在给定会话期间未使用的房间,但是很容易找到未使用的房间 em>are:
很容易将其与所有可能房间的列表结合起来以获得您需要的信息。
希望这有帮助!
PS:如果您也有一个
rooms
表(我不会为此添加一个表,但如果您碰巧有一个),它会变得更加容易:It looks to me like a table in need of a redesign. Judging by the column names, the "objects" (rows) you should be dealing with are "Events": An Event happens in a Room, during a section. With that setup, your table would look like:
Now there's still not a query that'll give you the rooms that aren't in use during a given session, but it's easy to find the ones that are:
And it's easy to combine that with a list of all possible rooms to get the information you need.
Hope this helps!
PS: If you have a
rooms
table as well (I wouldn't add one just for this, but if you happened to have one), it gets even easier: