Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
insert into a(aa,b,c,d)
  SELECT @curRank :=IF(@prevVal= exammarks.Test1, @curRank, @studentN) AS rank,
@percentile := IF(@prevVal=exammarks.Test1 , @percentile,(@totalS - @studentN + 1)/(@totalS)*100) as percent,
@studentN := @studentN + 1 as studentN,
@prevVal:=exammarks.Test1 as totagain
FROM student,exammarks, (
SELECT @curRank :=0, @prevVal:=null, @studentN:=1, @percentile:=100 ) r
WHERE student.idstudent = exammarks.stdid
ORDER BY exammarks.Test1  DESC

I can't do above operation.

Actually what i want is insert the result of select query to the table named 'a'. Select query separately works fine.

they are not true columns, but virtual columns which i select using some calculations.
How can i insert those data to another table, or else how can i view them using a view?

If all of them not possible how can i get those values in crystal reports by calling a formula or any other method.iam stucked.

please help..
Posted
Updated 8-May-13 17:09pm
v4
Comments
db7uk 8-May-13 14:31pm    
this is not c#, please tag question correctly. What version of SQL is it (if it is sql at all)? information like this really helps us help you.
Muthu Karunarathna 8-May-13 20:38pm    
Yes.Iam sorry that i have put wrong tag.iam using mysql.

Try giving same Alias Names. See this:
SQL
insert into a(aa,b,c,d)
  SELECT @curRank :=IF(@prevVal= exammarks.Test1, @curRank, @studentN) AS aa,
@percentile := IF(@prevVal=exammarks.Test1 , @percentile,(@totalS - @studentN + 1)/(@totalS)*100) as b,
@studentN := @studentN + 1 as c,
@prevVal:=exammarks.Test1 as d
FROM student,exammarks, (
SELECT @curRank :=0, @prevVal:=null, @studentN:=1, @percentile:=100 ) r
WHERE student.idstudent = exammarks.stdid
ORDER BY exammarks.Test1  DESC



Hope it helps!
--Amit
 
Share this answer
 
Comments
Muthu Karunarathna 9-May-13 5:50am    
This also not working.I dnt knw what to do..my main requirement is getting student ranks accroding to thier marks and view them using crystal report.above query which i used is showing ranks correctly.but i have no idea how can i view them through crystal reports.because it can't insert to db.without above formula,if there is another method which i can calculate ranks through crysatal report please show me the way.
try using join
SQL
select * from table 1

join

SELECT @curRank :=IF(@prevVal= exammarks.Test1, @curRank, @studentN) AS rank,
@percentile := IF(@prevVal=exammarks.Test1 , @percentile,(@totalS - @studentN + 1)/(@totalS)*100) as percent,
@studentN := @studentN + 1 as studentN,
@prevVal:=exammarks.Test1 as totagain
FROM student,exammarks, (
SELECT @curRank :=0, @prevVal:=null, @studentN:=1, @percentile:=100 ) r
WHERE student.idstudent = exammarks.stdid
ORDER BY exammarks.Test1  DESC
 
Share this answer
 
Comments
Muthu Karunarathna 8-May-13 20:42pm    
Join statement also not working there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900