gpt4 book ai didi

sql - 如何在内部查询条件中使用外部查询列

转载 作者:行者123 更新时间:2023-12-04 18:06:07 24 4
gpt4 key购买 nike

我想在 select 语句中使用子查询,但我想将列数据传递给子查询,以便它可以过滤正在处理的行的数据。我们如何做到这一点,或者这甚至可能吗?

select 
[SRP Code], [Master Code], [Product Desc], [Pack Desc],[Information], [Store],

case when ([SRP Code] <> [Master Code])
then
isnull([38],0) + (select (e.stock/er.unit) as 'Stock' from erp_stock e join
erpcustomerlinking er on e.productcode = er.mastercode where

er.mastercode = [Master Code] <-- here I want the column

and weekno = 38 group by e.stock,er.unit)
else
isnull([38],0)
end as [38],[36],[37],[35],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50]

from [dbo].[F91FE39A-F618-40A8-A6F7-C721A379EE76]

where [SRP Code] = 401794

最佳答案

是的,这是可能的。

Create table test(id int, name varchar(20), age int);
create table salary(id int, salary int, testid int);

insert into test values(1,'jitu',12);
insert into test values(2,'kapil',12);
insert into test values(3,'ajay',12);
insert into test values(4,'vijay',12);

insert into salary values(1, 200, 1);
insert into salary values(2, 300, 2);
insert into salary values(3, 400, 3);
insert into salary values(4, 500, 4);

select *, (select salary from salary where test.id=testid) as Salary from test

fiddle : http://sqlfiddle.com/#!2/717e9/3/0

关于sql - 如何在内部查询条件中使用外部查询列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com