sql - 如何使用不同的记录值两次查询表中的列?
问题描述
我在表名 ActionFlag 中有一个列,其中包含“N”、“R”和“A”等值,但是当我尝试查询此语句时,什么也没有出现?
select tblFtpTrans.*,tblLocs.unit from tblFtpTrans left join tblLocs on
tblFtpTrans.location=tblLocs.location where tblFtpTrans.id>0 and actiondate>='2020-06-01' and
actiondate<='2020-07-30' and actionflag='N' AND ActionFlag='A'
样本数据
NumId WorkId EightId Num ActionFlag
24803 17944 7683 0 N
24804 17940 5076 0 A
24805 17896 7684 0 A
24806 17904 7685 0 B
24807 17868 7686 0 R
这就是我要的
NumId WorkId EightId Num ActionFlag
24803 17944 7683 0 N
24804 17940 5076 0 A
24805 17896 7684 0 A
解决方案
只需使用in
:
select t.*, l.unit
from tblFtpTrans t left join
tblLocs l
on t.location = l.location
where t.id > 0 and
actiondate >= '2020-06-01' and
actiondate <= '2020-07-30' and
actionflag in ('N', 'A')
推荐阅读
- oracle - ORA-01722: Case 语句中的数字无效
- amazon-web-services - 有什么方法可以跟踪 AWS CodeBuild / CodePipeline 中工件的指纹?
- node.js - 需要猫鼬的帮助 .find()
- file - 是否可以将具有可变长度数据记录的文件读入 COBOL?
- java - 为什么 Redis 没有在 __keyevent@*__:expired 主题事件上调用我的 MessageListener?
- css - 如何使我的菜单在同一水平线上?
- tcc - 如何在 tcc 中通过匹配操作导入候选人申请?
- clojure - 这段代码在 Clojure.core.async 中做了什么?
- tensorflow - 无法使用 simple_save tensorflow 导出保存的模型
- vue.js - 使用 vuejs 的 V-for 循环多维调用