使用的条件选择特定的字段 [英] Where Used the the condition for select the the particular filed
本文介绍了使用的条件选择特定的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(subjects)
from mark_entry
group by subjects
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT * from
(
select student_name,roll_no,standard,section,subjects,cast(mark as int)as mark from mark_entry
) x
pivot
(
sum(mark)
for subjects in (' + @cols + ')
) p '
execute(@query)
这个查询我以前用过d使用数据透视表显示学校所有学生的记录
现在我只显示一个学生记录我不知道WHERE条件在哪里
请帮助我
This query i have used to display the record of the all the student in school using pivot table
Now I have to display only one student record i do no know where to the WHERE condition
Please Help me
推荐答案
set @query = 'SELECT * from
(select student_name,roll_no,standard,section,subjects,cast(mark as int)as mark from mark_entry) x
pivot
(sum(mark) for subjects in (' + @cols + '))p Where student_name =''StudentName'''
set @query = 'SELECT * from
(select student_name,roll_no,standard,section,subjects,cast(mark as int)as mark from mark_entry
WHERE StudentName = ''StudentName'') x
pivot
(sum(mark) for subjects in (' + @cols + '))p
Where student_name =''StudentName'''
这篇关于使用的条件选择特定的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文