I imported data into csv table via .net app, pls help, how can i aInsert into all the tables so that i can query;
- student avg score to a question or test
- student answers to a question or answer frequency to a question etc
My tables are in this form;
Csv Ans Quest Test Ans_Quest_Test
--------- ------ ------ ------ -------------
LName id id Id Ansid
FName Ans Quest name Questid
stdname StdScore ActScore Testid
Quest 开发者_JAVA百科 Stdname
Ans
ActualScore
StdScore
INSERT INTO Ans_Quest_Test
SELECT FLOOR(RAND(CHECKSUM(NEWID())) * 10000) --random number
, FLOOR(RAND(CHECKSUM(NEWID())) * 10000)--random number
, FLOOR(RAND(CHECKSUM(NEWID())) * 10000)--random number
, Stdname FROM Csv
INSERT INTO Ans
SELECT AnsId, Ans, StdScore FROM Ans_Quest_Test
JOIN Csv ON Ans_Quest_Test.Stdname=Csv.stdname
INSERT INTO Quest
SELECT QuestId, Quest, ActualScore FROM Ans_Quest_Test
JOIN Csv ON Ans_Quest_Test.Stdname=Csv.stdname
I do not see any name
for the Test
in the Csv
table, so I can not write an insert
for table Test
:)
student avg score to a question
SELECT Stdname, AVG(Quest.ActScore)
FROM Ans_Quest_Test
JOIN Quest ON Ans_Quest_Test.Questid=Quest.id
GROUP BY Stdname
student answers to a question
SELECT Ans_Quest_Test.Stdname, Quest.Quest, Ans.Ans
FROM Ans_Quest_Test
JOIN Quest ON Ans_Quest_Test.Questid=Quest.id
JOIN Ans ON Ans_Quest_Test.Ansid=Ans.id
answer frequency to a question
SELECT Quest.Quest, COUNT(Ans.id)
FROM Ans_Quest_Test
JOIN Quest ON Ans_Quest_Test.Questid=Quest.id
JOIN Ans ON Ans_Quest_Test.Ansid=Ans.id
GROUP BY Quest.Quest
精彩评论