2 qq 24420983 qq_24420983 于 2016.03.17 14:38 提问

如何实现sql group by 分组问题?在线等急
sql

![图片说明](http://img.ask.csdn.net/upload/201603/17/1458196507_779856.jpg)图片说明

如上图两张表如何实现用group by分组

实现如下功能:
declare @Jishu int=25
declare @Bianliang numeric=0
while @Jishu<=65
begin
SELECT @Bianliang=sum(dbo.LKG_CardsTong.TicketRemainCount) FROM dbo.LKG_CardsTong INNER JOIN
dbo.LKG_CardsTongKinds ON dbo.LKG_CardsTong.CardTKind = dbo.LKG_CardsTongKinds.CardTKindID

where ((dbo.LKG_CardsTong.CardTNumber like'5%')or(dbo.LKG_CardsTong.CardTNumber like'7%')or
(dbo.LKG_CardsTong.CardTNumber like'85%')) AND dbo.LKG_CardsTongKinds.CardTKindValue=@Jishu and dbo.LKG_CardsTong.CardTStatus =1 AND dbo.LKG_CardsTong.TicketRemainCount IS NOT NULL
set @Bianliang = case when @Bianliang is null then 0 else @Bianliang end
if @Jishu=25
begin
set @Jiesuan25= @Jishu*@Bianliang
end
else if @Jishu=30
begin
set @Jiesuan30= @Jishu*@Bianliang
end
else if @Jishu=35
begin
set @Jiesuan35= @Jishu*@Bianliang
end
else if @Jishu=40
begin
set @Jiesuan40= @Jishu*@Bianliang
end
else if @Jishu=45
begin
set @Jiesuan45= @Jishu*@Bianliang
end
else if @Jishu=50
begin
set @Jiesuan50= @Jishu*@Bianliang
end
else if @Jishu=55
begin
set @Jiesuan55= @Jishu*@Bianliang
end
else if @Jishu=60
begin
set @Jiesuan60= @Jishu*@Bianliang
end
else
begin
set @Jiesuan65= @Jishu*@Bianliang

end
set @Jishu+=5
end

2个回答

qq_24420983
qq_24420983   2016.03.17 14:39

图片说明

qq_24420983
qq_24420983   2016.03.17 14:40

第二张表在下边。。。。。。

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