为什么不加入两个选择表,在选择查询中显示实际结果
我正在使用mysql。我正在尝试通过!=条件加入两个查询。对于此示例,它应该返回空结果集。但是看来这种情况没有应用。为什么这样?
我的尝试如下:
SELECT today_student.* FROM (
SELECT scd.student_id, sc.transaction_date
FROM student_collection_details scd
INNER JOIN student_collection sc
ON (scd.student_collection_id = sc.id)
WHERE 1=1
AND sc.transaction_date BETWEEN DATE('2022-06-01 00:00:00') AND DATE('2022-06-27 00:00:00')
AND scd.admission_year_id = 2
AND scd.month_id = 21
AND scd.collection_head_id = 9
GROUP BY scd.student_id
) prev_student,
(
SELECT scd.student_id, sc.transaction_date
FROM student_collection_details scd
INNER JOIN student_collection sc
ON (scd.student_collection_id = sc.id)
WHERE 1=1
AND sc.transaction_date = DATE('2022-06-28 00:00:00')
AND scd.admission_year_id = 2
AND scd.month_id = 21
AND scd.collection_head_id = 9
GROUP BY scd.student_id
) today_student
WHERE 1=1
AND prev_student.student_id != today_student.student_id
prev_student返回:
1196; 2022-06-20 00:00:00
1861; 2022-06-18 00:00:00
today_student返回:
1196; 2022-06-28 00:00:00
1861; 2022-06-28 00:00:00
I am using MySQL. I am trying to join two queries by != condition. For this example it should return empty result set. But it seems the condition is not applied. Why is this so?
My attempts are below:
SELECT today_student.* FROM (
SELECT scd.student_id, sc.transaction_date
FROM student_collection_details scd
INNER JOIN student_collection sc
ON (scd.student_collection_id = sc.id)
WHERE 1=1
AND sc.transaction_date BETWEEN DATE('2022-06-01 00:00:00') AND DATE('2022-06-27 00:00:00')
AND scd.admission_year_id = 2
AND scd.month_id = 21
AND scd.collection_head_id = 9
GROUP BY scd.student_id
) prev_student,
(
SELECT scd.student_id, sc.transaction_date
FROM student_collection_details scd
INNER JOIN student_collection sc
ON (scd.student_collection_id = sc.id)
WHERE 1=1
AND sc.transaction_date = DATE('2022-06-28 00:00:00')
AND scd.admission_year_id = 2
AND scd.month_id = 21
AND scd.collection_head_id = 9
GROUP BY scd.student_id
) today_student
WHERE 1=1
AND prev_student.student_id != today_student.student_id
prev_student returns:
1196; 2022-06-20 00:00:00
1861; 2022-06-18 00:00:00
today_student returns:
1196; 2022-06-28 00:00:00
1861; 2022-06-28 00:00:00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用子句的条件 条款,即min
transaction_date
is'2022-06-28'
:Use a
HAVING
clause with the condition that the mintransaction_date
is'2022-06-28'
: