如何使用union将这个三行合并到同一行中(假如是int类型的数据的话,可以使用sum函数)
select * from table
union
select * from table 2
还可以使用行转列:
select * from table1(
select 字段1,字段n,sum(字段名称)
from (
select 字段1,字段n,
case when 条件 then 赋值 end as 别名,(为查询的字段)
....
) as a
)as b on .....条件表达式
select max(x),max(y),max(z) from 表;
select
case when (SUM(case when X is NULL then 0 else 1 end))= 1 then 'a' else NULL end,
case when (SUM(case when Y is NULL then 0 else 1 end))= 1 then 'b' else NULL end,
case when (Max(case when Z is NULL then 0 else 1 end))= 1 then 'c' else NULL end
from table
可能有好多写法,看你的实际表需求而定。