我写了个SQL语句。
select sum(goodsCost) as 成本,sum(sellNeedPay) as 应付金额,
sum(sellHasPay) as 实付金额,sum(sellNeedPay)-sum(goodsCost) as 利润
,sum(sellNeedPay)-sum(sellHasPay) as 差额 from tb_SellGoods
union select
sum(thGoodsCost) ,sum(thNeedPay),sum(thHasPay),
sum(thGoodsCost)-sum(thNeedPay),sum(thNeedPay)-sum(thHasPay) from tb_ThGoodsInfo联合查询中的2个语句分别只有1行数据,也就是总共2行数据。
我想让2行数据总是按照固定的顺序排列。
也就是上面语句的数据在第一行,下面语句的数据在第二行,怎么办。
select sum(goodsCost) as 成本,sum(sellNeedPay) as 应付金额,
sum(sellHasPay) as 实付金额,sum(sellNeedPay)-sum(goodsCost) as 利润
,sum(sellNeedPay)-sum(sellHasPay) as 差额 from tb_SellGoods
union select
sum(thGoodsCost) ,sum(thNeedPay),sum(thHasPay),
sum(thGoodsCost)-sum(thNeedPay),sum(thNeedPay)-sum(thHasPay) from tb_ThGoodsInfo联合查询中的2个语句分别只有1行数据,也就是总共2行数据。
我想让2行数据总是按照固定的顺序排列。
也就是上面语句的数据在第一行,下面语句的数据在第二行,怎么办。
但是能设置行标题吗?
有些行标题也可以通过增加列标题来实现!!!
上面,第二条的在下面吧~行标题?还是把数据查出来再做处理吧~
(
(select '成本' as 成本,'应付金额' as 应付金额,'实付金额' as 实付金额,'利润' as 利润,'差额' as 差额,0as tag)
union
(select sum(goodsCost) as 成本,sum(sellNeedPay) as 应付金额,
sum(sellHasPay) as 实付金额,sum(sellNeedPay)-sum(goodsCost) as 利润
,sum(sellNeedPay)-sum(sellHasPay) as 差额 ,1 as tag from tb_SellGoods)
union
(select sum(thGoodsCost) ,sum(thNeedPay),sum(thHasPay),
sum(thGoodsCost)-sum(thNeedPay),sum(thNeedPay)-sum(thHasPay,2 as tag) from tb_ThGoodsInfo)) total
order by tag