问题描述
- 如何实现sql group by 分组问题?在线等急
-
如上图两张表如何实现用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.CardTKindIDwhere ((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*@Bianliangend
set @Jishu+=5
end
解决方案
解决方案二:
第二张表在下边。。。。。。