我有一个表,它有很多相同的值。 在我的表中,我想根据列来选择不同的值。我的问题是,包括mysql:我想在我的行中包含一个值
这是我的表
column column.a column.b
1 tax1 100
1 tax2 200
1 tax3 300
2 tax1 100
2 tax2 200
这是我的选择语句
select distinct column, sum(column.b) - column.b as amount,
(select column.b where column.a = tax2)as column.c
from table order by column
我想在我的select语句column.b包括其中column.a = TAX2
这是我期望的输出。
column amount column.c
1 500 200
2 200 200
我只是不知道我可以将它包含在我的select语句中。谢谢。
鉴于样本数据,您的结果对我来说没有意义(对我而言)。什么是c列?金额如何计算? –
我想我明白了。通过在相同的'select'中混合聚合值和非聚合值,您正在滥用SQL。你的问题没有意义。 –
什么是'sum(column.b) - column.b'应该是什么意思?第1列有3个不同的'column.b'值,哪一个值应该被减去? – Barmar