gpt4 book ai didi

c# - MySql 内连接,如果值等于 0,则为 "OR"

转载 作者:行者123 更新时间:2023-11-29 11:56:32 24 4
gpt4 key购买 nike

所以我有这个内部连接

SELECT IDEvent,events.IDSubject,events.month,events.year
FROM events
INNER JOIN subjects ON events.IDSubject = subjects.IDSubject
INNER JOIN classes ON subjects.IDClass = classes.IDClass
INNER JOIN students ON classes.IDClass = students.IDClass
WHERE events.month=10
AND events.year=2015
AND (students.DNI=DNI OR events.IDSubject='0')`

我想要做的是根据用户 IDSubject 选择所有事件,并且如果还有一些 IDSubject=0 的事件,我可以获取依赖于用户的事件,但无法获取IDSubject=0 的,有人知道如何正确执行此操作吗?

我的数据库模型(如果有人需要的话)

最佳答案

SELECT IDEvent,events.IDSubject,events.month,events.year
FROM events
INNER JOIN subjects ON events.IDSubject = subjects.IDSubject
INNER JOIN classes ON subjects.IDClass = classes.IDClass
INNER JOIN students ON classes.IDClass = students.IDClass
WHERE events.month=10
AND events.year=2015
AND students.DNI=DNI
UNION SELECT IDEvent, events.IDSubject ,events.month ,events.year
FROM events WHERE IDSubject='0'

关于c# - MySql 内连接,如果值等于 0,则为 "OR",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33114570/

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