gpt4 book ai didi

MySQL加入: displaying all rows in a table whilst using "where" clause

转载 作者:行者123 更新时间:2023-11-29 07:02:09 25 4
gpt4 key购买 nike

我有以下表格:

= id, time

child = id, parent_id, name, form

parent = id, name, contact_details

老师 = id, name, subject

约会 = id, child_id, slot

我正在使用以下代码显示可预订预约时间列表:

SELECT s.id, DATE_FORMAT( s.time,  '%l:%i' ) AS TIME, p.name
FROM slots AS s
LEFT JOIN appointments AS a ON a.slot = s.id
LEFT JOIN child AS c ON a.child_id = c.id
LEFT JOIN parent AS p ON c.parent_id = p.id

这会显示我所有预约空档的列表以及一些带有 parent 姓名的空档。

我想做的是,对于特定的老师显示所有预约空档的列表,如果有人已满,我想显示姓名已预订该时段的 child 的 parent 的姓名

例如,

布鲁姆菲尔德小姐的约会:

id  TIME    name
1 4:00 Parent One
2 4:05 NULL
3 4:10 Parent Two
4 4:15 NULL
5 4:20 NULL
6 4:25 NULL
7 4:30 NULL

这可能吗?我试过使用 WHERE 子句,但它只显示已预订的约会,而不是可用时间的完整列表。

因此我意识到我相当确定我的 JOIN 完全错误!


更新:插槽表如下所示:

SQL result

Host: localhost
Generation Time: Mar 05, 2012 at 11:43 AM
Generated by: phpMyAdmin 3.4.9 / MySQL 5.5.20
SQL query: SELECT * FROM `slots` LIMIT 0, 30 ;
Rows: 30

id time
1 2012-03-15 16:00:00
2 2012-03-15 16:05:00
3 2012-03-15 16:10:00
4 2012-03-15 16:15:00
5 2012-03-15 16:20:00
6 2012-03-15 16:25:00
7 2012-03-15 16:30:00
8 2012-03-15 16:35:00
9 2012-03-15 16:40:00
10 2012-03-15 16:45:00
11 2012-03-15 16:50:00
12 2012-03-15 16:55:00
13 2012-03-15 17:00:00
14 2012-03-15 17:05:00
15 2012-03-15 17:10:00
16 2012-03-15 17:15:00
17 2012-03-15 17:20:00
18 2012-03-15 17:25:00
19 2012-03-15 17:50:00
20 2012-03-15 17:55:00

提前致谢

最佳答案

或者您可以将以下内容放在 WHERE 中

WHERE appointments.teacher_id =$teacher OR appointments.teacher_id IS NULL

关于MySQL加入: displaying all rows in a table whilst using "where" clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9565862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com