PostgreSQL多条件语句 [英] PostgreSQL multiple criteria statement

查看:754
本文介绍了PostgreSQL多条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下postgreSQL语句,用于返回学校开学和需要上学的日期

I have the following postgreSQL statement that returns dates that school is open and attendance needs to be taken

SELECT school_date 
FROM attendance_calendar 
WHERE syear='$syear' 
AND school_date<CURRENT_DATE 
AND calendar_id='$cal_ID'

然后,我有另一个表名为Attenance_completed,该表具有一列school_date,我希望从上述语句中查询每个返回的日期。但是,而不是做两个不同的语句,只是想知道是否有人可以帮助合并该语句?

I then have another table called attendance_completed which has a column called school_date that i want to query for each returned date from the above statement. But instead of doing two different statements, just wondering if someone can help combine the statement?

基本上,我希望以上语句检查返回的school_date是否存在于表称为Attence_completed,并且仅返回缺少的日期。

Basically, i would like the above statement to check if the returned school_date exists in the table called attendance_completed, and only return the dates that are missing.

谢谢

推荐答案

这应该为您工作:

SELECT cal.school_date
FROM attendance_calendar cal
WHERE  cal.school_date NOT IN (
    SELECT com.school_date
    FROM attendance_completed com
    WHERE com.school_date IS NOT NULL
) AND
cal.syear = '$syear' AND
cal.school_date < CURRENT_DATE AND
cal.calendar_id = '$cal_ID;

这篇关于PostgreSQL多条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆