使用一个查询为第二个查询设置范围
using one query to set range for second query
早上好
我有以下问题。有效 我正在尝试使用第一个查询生成的客户端列表传递给第二个查询以提取我需要提取的交易列表。
我是 sql 的新手,所以不确定是否可行。谁能建议一个解决方案
--create list of client_accs
select client_id, client_acc
from client_crm
where client_id = 'LOG0000240'
--select transaction data for list of client generated in first query
Select
client_id,
test_cash_trans.client_acc,
sub_trans_type,
settle_date,
dbt_crt,
test_cash_trans.currency,
cash_amount,
test_cash_trans.last_update
From test_cash_trans
inner join client_crm
on test_cash_trans.client_acc = client_crm.client_acc
where test_cash_trans.client_acc in --- result of first query
group by client_id,test_cash_trans.client_acc, sub_trans_type, settle_date, dbt_crt, test_cash_trans.currency, cash_amount,test_cash_trans.last_update
您可能正在寻找 IN
:
test_expression [ NOT ] IN
( subquery | expression [ ,...n ]
)
Determines whether a specified value matches any value in a subquery or a list.
这是一个例子:
SELECT p.FirstName, p.LastName
FROM Person.Person AS p
JOIN Sales.SalesPerson AS sp
ON p.BusinessEntityID = sp.BusinessEntityID
WHERE p.BusinessEntityID IN
(SELECT BusinessEntityID
FROM Sales.SalesPerson
WHERE SalesQuota > 250000);
更多信息:IN (Transact-SQL)
早上好
我有以下问题。有效 我正在尝试使用第一个查询生成的客户端列表传递给第二个查询以提取我需要提取的交易列表。
我是 sql 的新手,所以不确定是否可行。谁能建议一个解决方案
--create list of client_accs
select client_id, client_acc
from client_crm
where client_id = 'LOG0000240'
--select transaction data for list of client generated in first query
Select
client_id,
test_cash_trans.client_acc,
sub_trans_type,
settle_date,
dbt_crt,
test_cash_trans.currency,
cash_amount,
test_cash_trans.last_update
From test_cash_trans
inner join client_crm
on test_cash_trans.client_acc = client_crm.client_acc
where test_cash_trans.client_acc in --- result of first query
group by client_id,test_cash_trans.client_acc, sub_trans_type, settle_date, dbt_crt, test_cash_trans.currency, cash_amount,test_cash_trans.last_update
您可能正在寻找 IN
:
test_expression [ NOT ] IN
( subquery | expression [ ,...n ]
)
Determines whether a specified value matches any value in a subquery or a list.
这是一个例子:
SELECT p.FirstName, p.LastName
FROM Person.Person AS p
JOIN Sales.SalesPerson AS sp
ON p.BusinessEntityID = sp.BusinessEntityID
WHERE p.BusinessEntityID IN
(SELECT BusinessEntityID
FROM Sales.SalesPerson
WHERE SalesQuota > 250000);
更多信息:IN (Transact-SQL)