返回布尔值为 0 的列的名称

发布于 2024-10-16 12:23:15 字数 302 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慢慢从新开始 2024-10-23 12:23:15

在我看来,它就像一张需要重新设计的桌子。从列名来看,您应该处理的“对象”(行)是“事件”:事件发生在一个房间中、一个部分的期间。通过这种设置,您的表格将如下所示:

session_id room_id
1          2
2          1
2          3

现在仍然没有查询可以为您提供在给定会话期间使用的房间,但是很容易找到未使用的房间 em>are:

SELECT room_id FROM events WHERE session_id = <whatever>

很容易将其与所有可能房间的列表结合起来以获得您需要的信息。

希望这有帮助!

PS:如果您也有一个 rooms 表(我不会为此添加一个表,但如果您碰巧有一个),它会变得更加容易:

SELECT id FROM rooms WHERE NOT EXISTS (SELECT * FROM events WHERE room_id = id AND session_id = <whatever>)

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:

session_id room_id
1          2
2          1
2          3

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:

SELECT room_id FROM events WHERE session_id = <whatever>

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:

SELECT id FROM rooms WHERE NOT EXISTS (SELECT * FROM events WHERE room_id = id AND session_id = <whatever>)
洋洋洒洒 2024-10-23 12:23:15
SELECT column_name FROM information_schema.columns WHERE table_name = 'tabel Name' 
SELECT column_name FROM information_schema.columns WHERE table_name = 'tabel Name' 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文