首页 > 解决方案 > 我正在寻找使用子查询中的值的方法

问题描述

正如标题所示,我正在寻找一种方法来使用子查询中的值而不使用“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

标签: sql

解决方案


您可能需要一个相关的子查询。也许:

SELECT A.column1, A.column2,
       (SELECT B.column1
        FROM B
        WHERE B.column3 = A.column3
       )
from A;

推荐阅读