问题描述
- 求大神 怎么合并这条SQL
-
下面这3个表没有关联select COUNT(distinct(c_cardno)) as 金卡总数 FROM card_srv.enjoy_card.dbo.tb_o_card_interests a1(nolock) where c_cardno like '61%' select c_interest_amount as 金卡总利息 FROM card_srv.enjoy_card.dbo.tb_o_card_interest a2(nolock) select count(c_cardno) as 发行总数 FROM card_srv.enjoy_card.dbo.tb_card a3(nolock) where c_cardno like '61%' and c_status='正常'
结果如下:
金卡总数
10800金卡总利息
31881.06发行总数
14611我想要的格式
金卡总数 金卡总利息 发行总数
123 123 123请告知谢谢了
解决方案
select COUNT(distinct(c_cardno)) as 金卡总数, c_interest_amount as 金卡总利息, count(c_cardno) as 发行总数
from card_srv.enjoy_card.dbo.tb_o_card_interests a1(nolock),card_srv.enjoy_card.dbo.tb_o_card_interest a2(nolock), card_srv.enjoy_card.dbo.tb_card a3(nolock)
where c_cardno like '61%'
and c_cardno like '61%' and c_status='正常'
解决方案二:
select
(select COUNT(distinct(c_cardno)) FROM card_srv.enjoy_card.dbo.tb_o_card_interests a1(nolock)
where c_cardno like '61%')
as 金卡总数
(select c_interest_amount FROM card_srv.enjoy_card.dbo.tb_o_card_interest a2(nolock))
as 金卡总利息
(select count(c_cardno) FROM card_srv.enjoy_card.dbo.tb_card a3(nolock)
where c_cardno like '61%' and c_status='正常')
as 发行总数
from dual;
希望能帮到你
解决方案三:
字段之间加上逗号,刚刚忘加了
解决方案四:
你把这三个查询,当做字段就行了,select () from xxx 括号里面放你的select count 查询