22,209
社区成员
发帖
与我相关
我的任务
分享
declare @tb table([day] int,amount decimal(10,5))
insert into @tb select 1,3.33333
union all select 2,4.22222
union all select 3,1.5555
union all select 4,9.888
select [day],(select sum(amount) from @tb where [day]<=a.[day]) amount from @tb a
declare @t table(id int,n varchar(10),weekdays int)
insert into @t select 1,'a',2
union all select 2,'a',3
union all select 3,'b',3
union all select 4,'b',4
union all select 5,'c',1
union all select 6,'c',4
union all select 7,'c',2
select n,max(case when weekdays=1 then '有课' else '' end) as 星期一,
max(case when weekdays=2 then '有课' else '' end) as 星期二,
max(case when weekdays=3 then '有课' else '' end) as 星期三,
max(case when weekdays=4 then '有课' else '' end) as 星期四,
max(case when weekdays=5 then '有课' else '' end) as 星期五
from @t group by n
declare @b table(a int,b int)
insert into @b select 1,2
union all select 1,3
union all select 1,4
union all select 2,1
union all select 2,2
union all select 3,1
union all select 4,1
union all select 5,3
union all select 5,2
select a,min(b)b from @b group by a
/*
day amount
----------- ---------------------------------------
1 3.33333
2 7.55555
3 9.11105
4 18.99905
(4 行受影响)
n 星期一 星期二 星期三 星期四 星期五
---------- ---- ---- ---- ---- ----
a 有课 有课
b 有课 有课
c 有课 有课 有课
(3 行受影响)
a b
----------- -----------
1 2
2 1
3 1
4 1
5 2
(5 行受影响)
*/
1:
select
a.Day As 日期
,a.Amount As 日产
,Sum(b.Amount) As 累计日产
from A As a,A As b
Where a.Day>=b.Day
Group by a.Day,a.Amount
2:
Select
TeacherName
,Max(Case when WeekDays=1 And IsLesson=1 Then N'有课' Else '' End) As 星期一
,Max(Case when WeekDays=2 And IsLesson=1 Then N'有课' Else '' End) As 星期二
,Max(Case when WeekDays=3 And IsLesson=1 Then N'有课' Else '' End) As 星期三
,Max(Case when WeekDays=4 And IsLesson=1 Then N'有课' Else '' End) As 星期四
From TeacherLesson
Group by TeacherName
3:
Select
A
,Min(B) As B
from CC
Group by A