getting a row from another table

Posted by Jammyhunt under ASP.NET on 2/26/2013 | Points: 10 | Views : 555 | Status : [Member] | Replies : 7
Greet everyone

table 1

sl.no name maths science total percentage

1 raj 10 15 (10+15) maths/science*100

2 aman 12 21 (12+21) maths/science*100

3 khan 9 18 (9+18) maths/science*100

4 jammy 11 13 (11+13) maths/science*100

GRAND TOTAL (10+12+9+11) (15+21+18+13) [(10+12+9+11) + (15+21+18+13)] (10+12+9+11)/(15+21+18+13) *100

TABLE 2

sl.no name maths science total percentage

1 raj 10 15 (10+15) maths/science*100

2 aman 12 21 (12+21) maths/science*100

3 khan 9 18 (9+18) maths/science*100

4 jammy 11 13 (11+13) maths/science*100

GRAND TOTAL (10+12+9+11) (15+21+18+13) [(10+12+9+11) + (15+21+18+13)] (10+12+9+11)/(15+21+18+13) *100

I want to get GRAND TOTAL of table 1 and table 2 and get show on another table

like this

MATHS SCIENCE TOTAL PERCENTAGE

TABEL 1 GRAND TOTAL (10+12+9+11) (15+21+18+13) [(10+12+9+11) + (15+21+18+13)] (10+12+9+11)/(15+21+18+13) *100

TABLE 2 GRAND TOTAL (10+12+9+11) (15+21+18+13) [(10+12+9+11) + (15+21+18+13)] (10+12+9+11)/(15+21+18+13) *100




Responses

Posted by: Santhi on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

You can get it by using SUM() and avg() function in sql ..
Execute this query
SELECT        SUM(Table1.Maths) AS mathstotal, SUM(Table1.science) AS sciencetotal, SUM(Table1.Maths) + SUM(Table1.science) AS total1, AVG(Table1.Maths) 

+ AVG(Table1.science) AS Expr1, SUM(Table2.Maths) AS mathtotal, SUM(Table2.Science) AS scitotal, SUM(Table2.Maths) + SUM(Table2.Science) AS total2,
AVG(Table2.Maths) + AVG(Table2.Science) AS Expr2
FROM Table1 INNER JOIN
Table2 ON Table1.ID = Table2.ID


are you asking this one.
If not, explain me clearly.



Thanks & Regards,
Santhi .V

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
i want to calculate percentage not average.....

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

you got solution up to total right.
Can you tell me the steps how do you want to calculate the percentage.
I cannot understand the steps which you have given.


Thanks & Regards,
Santhi .V

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
a= 50, b =30
percentage = a/b*100

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

whether you need like this .
a divide by b means maths divide by science * 100
I understood in this way.
you have to sum the maths and science marks .
Divide the maths mark by science mark .
finally, convert it in to percentage.

Try this query.
Are you asking this

SELECT        CAST(SUM(Maths) AS float) / CAST(SUM(Science) AS float) * 100 AS exp

FROM Table1


If this is correct, write the join query and continue..



Thanks & Regards,
Santhi .V

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
i got it.. thanks for help

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
what if i want to take footer of table1 and table2 and display on another table?

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response