帮忙看看这个句子如何写,多谢了
帮忙看看这个句子怎么写,谢谢了
select a.a1 as 录入日期,
(select b.b1
from b where b.b2=a.a2) as 扫描日期
from a
where 扫描日期 is null
想咨询下如何写“扫描日期”,扫描日期为空的。
------解决思路----------------------
因为where 子句执行优先select ,所以需要外面套一层才可以引用别名
select * from
(select a.a1 as 录入日期,
(select b.b1
from b where b.b2=a.a2) as 扫描日期
from a)
where 扫描日期 is null
------解决思路----------------------
使用 with as 语句也可以,与1# 的效果一样
------解决思路----------------------
楼上的是对的,但是还可以优化SQL语句:
select a.a1 as 录入日期,
(select b.b1
from b where b.b2=a.a2) as 扫描日期
from a
where 扫描日期 is null
想咨询下如何写“扫描日期”,扫描日期为空的。
------解决思路----------------------
因为where 子句执行优先select ,所以需要外面套一层才可以引用别名
select * from
(select a.a1 as 录入日期,
(select b.b1
from b where b.b2=a.a2) as 扫描日期
from a)
where 扫描日期 is null
------解决思路----------------------
使用 with as 语句也可以,与1# 的效果一样
with mt as
(
select a.a1 as 录入日期,
(select b.b1
from b where b.b2=a.a2) as 扫描日期
from a
)
select * from mt where 扫描日期 is null
------解决思路----------------------
楼上的是对的,但是还可以优化SQL语句:
select a.a1 as 录入日期,
b1 as 扫描日期
from a left join b on b.b2 = a.a2
where b.b2 is null