SQL 中两个查询之间的差异(Oracle Apex 项目)
我在 APEX 应用程序的不同项目中有以下两个查询:
ITEM 1:
SELECT SUM(t.gems)
FROM (SELECT gems
FROM tasks
UNION ALL
SELECT gems
FROM quests
UNION ALL
SELECT gems
FROM daily_quests
) t
ITEM 2:
SELECT SUM(price) FROM items
它们都正确返回一个数字,但我想在一个语句中减去它们。我尝试使用
SELECT TO_NUMBER(ITEM1)-TO_NUMBER(ITEM2) FROM DUAL
但没有成功。
您有什么建议吗?我对 APEX 和 SQL 有点陌生。
先感谢您。
I have the two following queries in different items in an APEX application:
ITEM 1:
SELECT SUM(t.gems)
FROM (SELECT gems
FROM tasks
UNION ALL
SELECT gems
FROM quests
UNION ALL
SELECT gems
FROM daily_quests
) t
ITEM 2:
SELECT SUM(price) FROM items
They both return a number correctly, but I want to subtract them in one statement. I tried to use
SELECT TO_NUMBER(ITEM1)-TO_NUMBER(ITEM2) FROM DUAL
but it didn't work.
Do you have any suggestions? I am a bit new to APEX and SQL.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设每个查询生成一个名为
gems
的列,您可以执行以下操作:Assuming each query produces a column named
gems
you can do:Koen 的答案给出了此类问题的一般正确答案。
但是,在您的特定实例中,您可以使用更简单的查询:
Koen's answer gives the general, correct answer for this type of problem.
In your particular instance, however, you can use a simpler query:
对每个查询使用 CTE(公共表表达式),然后
CROSS JOIN
它们。Use a CTE (Common table expression) for each of the queries, then
CROSS JOIN
them.