sql - 我正在寻找使用子查询中的值的方法
问题描述
正如标题所示,我正在寻找一种方法来使用子查询中的值而不使用“JOIN”。
请有人告诉我这是不可能的吗?
SELECT A.column1 A.colomn2 B.column.1/*I want to use it*/
from A
where A.column1 in (select cokumn1 column3 from B )
实际 SQL
select
no,
sum(case when type = 'A' then cost else -cost end) * 0.25 as cal
from tr
where
tr.type in ('A', 'B')
and exists (select 1 from users u where u.no = c.no)
group by no
TR_TABLE
NO,COST,TYPE
1,1000,A
1,500, B
1,200, A
2,100, A
Users
id.No,age
理想的
No, Cost , cal , age
No1 COST 700,m
No2 COST 100,f
解决方案
您可能需要一个相关的子查询。也许:
SELECT A.column1, A.column2,
(SELECT B.column1
FROM B
WHERE B.column3 = A.column3
)
from A;
推荐阅读
- django - Django 没有过滤模板中的多对多结果
- android - 运行 OpenVPN 代码时启动进程“命令 'swig”时出现问题
- json - 我如何在 Firebase 中快速返回数组
- python - 如何在所有案例中使用两个列表制作字典?
- c# - 在 Asp.Net Core 控制器中文件未按预期流式传输
- list - scala - 无法解析符号::
- monaco-editor - 摩纳哥的语法注射?
- python - 组合数据框的列
- python - (TF) 保存模型及其 history.history 以在以下培训课程中使用它
- python - 为什么 .numpy() 不适用于 python 中的张量对象?