azure-sql-database - 使用一个查询设置第二个查询的范围
问题描述
早上好
我有以下问题。有效我正在尝试使用从第一个查询中生成的客户端列表传递到第二个查询中以提取我需要提取的事务列表。
我是 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 ]
)
确定指定值是否与子查询或列表中的任何值匹配。
这是一个例子:
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)
推荐阅读
- rxjs - RXJS 在事件触发时发出数组项
- json - 如何使用 jq 从 terraform 状态文件中提取特定字段?
- python - Jupyter 没有执行暂存器单元
- apache-spark - 运行依赖于另一个任务的 Luigi 任务
- java - 将 Firebase Auth 从 Android SDK 切换到 Firebase Admin SDK
- django-rest-framework - 如何根据 Django Rest Framework 中的 JWT 有效负载覆盖 GET 方法?
- c# - C#元组不保留名称,只使用'itemx'
- javascript - 获取 div 的边界框,按 chromium/puppeteer 中的列数拆分
- r - 如何覆盖R中的html文件
- javascript - 响应式画廊 Vue.js