2 lin3360827 lin3360827 于 2016.02.18 14:18 提问

求大神 怎么合并这条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

请告知谢谢了

4个回答

wen_wxpk
wen_wxpk   2016.02.18 14:25

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='正常'

hopefully123
hopefully123   2016.02.18 14:41

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;

希望能帮到你

hopefully123
hopefully123   2016.02.18 14:45

字段之间加上逗号,刚刚忘加了

bdmh
bdmh   Ds   Rxr 2016.02.18 14:22

你把这三个查询,当做字段就行了,select () from xxx 括号里面放你的select count 查询

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!