declare
@sql
varchar
(8000
) declare
@examid
varchar(10
)declare
@claid
varchar(10
)set
@claid='
60'set@examid='
151'
set@sql='
select m.pargid,c.nickname as parname,c.mobile,a.name as stuname
'select
@sql
=@sql+'
,max(case d.coursename when
'''+
d.coursename
+'''
then convert(varchar(50),isnull(a.score,0)) else ''0
''end) ['+
d.coursename+'
]'from
(select
distinct
x.coursename
from
score_course x,score_examcourse y
where
x.id
=y.courseid
andy.examid
=@examid
) as
d select
@sql
=@sql+'
,sum(a.score) as sumscore
from score_detail a,score_examcourse b,base_user c,score_course d,base_formaluser m
where m.stugid=a.gid and m.pargid=c.gid and a.examcouid=b.id and b.courseid=d.id and b.examid='+
@examid+'
and a.claid='+
@claid+'
group by a.name,a.gid ,m.pargid,c.nickname,c.mobile
'exec
(@sql
)
SQL語句積累 三
起別名不能用數字 select from table1 1,table2 2是不允許的.用a,b代替吧.stuff 要替換的字串,起始位置,長度,替換內容 select stuff abcdef 2,3,ijklmn goif object id tempdb.is not null drop ta...
oracle函式,sql語句整理積累
每天積累一點點,期待自己的進步 1.關於substr函式的用法和個人見解 substr string,start position,length 我理解為,擷取某個字串中的某些內容 舉例 20170208 只獲取年月也就是 201702 string引數為字串的意思,可以直接寫內容如 2017020...
sql 語句 查詢
例11 1 1 use xk gocreate trigger test1 on student for update as print 記錄已修改!go 2 update student set pwd 11111111 where stuno 00000001 例11 3 1 use xk go...