【发布时间】:2021-11-02 05:41:59
【问题描述】:
请帮助我处理这个 SQL 选择查询。它可以作为三个 select 语句,但我需要将它变成一个语句
select (loan_amount + origination_fee) column1 from Table
where transaction_type='A'
select (stock_price + broker_fee) column2 from Table
where transaction_type='B'
select (taxable_amount + miscellaneous) column3 from Table
where transaction_type='C'
我试过了:
SELECT (
SELECT (loan_amount + origination_fee)
FROM table
WHERE transaction_type = 'A'
) AS A
,(
SELECT (stock_price + broker_fee)
FROM table
WHERE transaction_type = 'B'
) AS B
,(
SELECT (taxable_amount + miscellaneous)
FROM table
WHERE transaction_type = 'C'
) AS C
我收到以下错误:
消息 512,第 16 级,状态 1,第 1 行
子查询返回超过 1 个值。当子查询跟随 =、!=、、>= 或子查询用作表达式时,这是不允许的。
【问题讨论】:
-
样本数据有助于您的问题。
-
除了样本数据和想要的结果,还请为您正在使用的数据库添加标签。