如何在 SQL (Oracle) 中连接两个查询
我如何加入这些查询?
SELECT RCTDT, SUM(RCTAMOUNT), COUNT(RCTAMOUNT) FROM RECEIPTS4
WHERE RCTDT BETWEEN '01-nov-2009' AND '30-nov-2009'
AND RCTTYPE='CA' AND RCTAMOUNT>0
GROUP BY RCTDT
---
SELECT RCTDT, SUM(RCTAMOUNT), COUNT(RCTAMOUNT) FROM RECEIPTS4
WHERE RCTDT BETWEEN '01-nov-2009' AND '30-nov-2009'
AND RCTTYPE='CQ' AND RCTAMOUNT>0
GROUP BY RCTDT
How can I join these queries?
SELECT RCTDT, SUM(RCTAMOUNT), COUNT(RCTAMOUNT) FROM RECEIPTS4
WHERE RCTDT BETWEEN '01-nov-2009' AND '30-nov-2009'
AND RCTTYPE='CA' AND RCTAMOUNT>0
GROUP BY RCTDT
---
SELECT RCTDT, SUM(RCTAMOUNT), COUNT(RCTAMOUNT) FROM RECEIPTS4
WHERE RCTDT BETWEEN '01-nov-2009' AND '30-nov-2009'
AND RCTTYPE='CQ' AND RCTAMOUNT>0
GROUP BY RCTDT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 IN 运算符:
Use the
IN
operator:也许你的意思是这个
Maybe you meant this
在此特定示例中,按照 cletus 的建议使用
IN
。在其他情况下,无法从同一选择生成两个结果集,请使用UNION
组合结果:In this particular example, use an
IN
as suggested by cletus. In other cases, where the two result sets cannot be generated from the same select, use aUNION
to combine the results:从收据中选择 RCTDT、SUM(RCTAMOUNT)、COUNT(RCTAMOUNT)4
“2009 年 11 月 1 日”和“2009 年 11 月 30 日”之间的 RCTDT 位置
AND RCTTYPE IN ('CA','CQ') AND RCTAMOUNT>0
GROUP BY RCTDT
也很有用。
SELECT RCTDT, SUM(RCTAMOUNT), COUNT(RCTAMOUNT) FROM RECEIPTS4
WHERE RCTDT BETWEEN '01-nov-2009' AND '30-nov-2009'
AND RCTTYPE IN ('CA','CQ') AND RCTAMOUNT>0
GROUP BY RCTDT
can also be useful.