使用Sql Query获取输出 [英] Getting the output using Sql Query
本文介绍了使用Sql Query获取输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Studdet表格如下;
Studdet table as follows;
Studid StudName Marks QpName Bthid AnswerID
32468 VENKATA 70 SAC 625 10861
32468 VENKATA 88 REO 616 10715
44258 RAJ 100 AFF 71 1136
44258 RAJ 80 PSCRB 78 1241
44258 RAJ 80 MFA 100 1615
答案表如下;
Studid Qno AnswerID
32468 4 10715
32468 4 10861
44258 4 1136
44258 4 1241
批处理表如下;
Bthno Batch Date Attender Class
B09 12/10/2012 Rk SAC
B143 12/9/2012 RV REO
课程表如下;
Course COde
SAC
RE0
使用上表,我想获得以下输出:
我想查看特定学生ID的以下输出详细信息。
我想写查询,因为我想要使用参数作为学生ID并获得以下输出:
Using the above tables, I want to get the following output:
I want to see the below output details for particular student id.
I want to write the query, in that I want to use parameter as student id and get the below output as follows;
CourseCode Marks Qpname Qno Bthno BatchDate Attender
SAC 70 SAC 4 B09 12/10/2012 RK
REO 88 REO 4 B09 12/10/2012 RV
推荐答案
--You can try the following Query it may help you
DECLARE @Student TABLE (Studid INT,StudName VARCHAR(50),Marks int,QpName VARCHAR(50),Bthid int,AnswerID INT)
INSERT INTO @Student VALUES (32468,'VENKATA',70,'SAC',625,10861)
INSERT INTO @Student VALUES ( 32468,'VENKATA',88,'REO',616,10715)
INSERT INTO @Student VALUES (44258,'RAJ',100,'AFF',71,1136)
INSERT INTO @Student VALUES (44258,'RAJ',80,'PSCRB',78,1241)
INSERT INTO @Student VALUES (44258,'RAJ',80,'MFA',100,1615)
DECLARE @Answer TABLE (Studid INT,Qno int,AnswerID INT)
INSERT INTO @Answer VALUES (32468,4,10715)
INSERT INTO @Answer VALUES (32468,4,10861)
INSERT INTO @Answer VALUES (44258,4,1136)
INSERT INTO @Answer VALUES (44258,4,1241)
DECLARE @Batch TABLE (Bthno VARCHAR(50),BatchDate VARCHAR(50),Attender VARCHAR(50),Class VARCHAR(50))
INSERT INTO @Batch VALUES ('B09','12/10/2012','Rk','SAC')
INSERT INTO @Batch VALUES ('B143','12/9/2012','RV','REO')
DECLARE @Course TABLE (CourseCode VARCHAR(50))
INSERT INTO @Course VALUES ('SAC')
INSERT INTO @Course VALUES ('REO')
Select * From @Student
Select * From @Answer
Select * from @Batch
Select DISTINCT C.CourseCode,S.Marks,S.QpName,A.Qno,B.Bthno,B.BatchDate,B.Attender from @Course C
JOIN @Batch B ON B.Class=C.CourseCode
JOIN @Student S ON S.QpName=C.CourseCode
JOIN @Answer A ON A.Studid=S.Studid
这篇关于使用Sql Query获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文