We help IT Professionals succeed at work.
Get Started

How to find out the percentage for alias name this type of query in sql?

208 Views
Last Modified: 2012-05-12
How to find percentage is BCOP-201(A)/BCOP-201(D) as 'P' for all columns
select       Rollno, Name,
      sum(case when scode = 'BCOP-201' then status else 0 end) as 'BCOP-201(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-201') as 'BCOP-201(D)',
      sum(case when scode = 'BCOP-202' then status else 0 end) as 'BCOP-202(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-202') as 'BCOP-202(D)',
      sum(case when scode = 'BCOP-203' then status else 0 end) as 'BCOP-203(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-203') as 'BCOP-203(D)',
      sum(case when scode = 'BCOP-204' then status else 0 end) as 'BCOP-204(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-204') as 'BCOP-204(D)',
      sum(case when scode = 'BCOP-205' then status else 0 end) as 'BCOP-205(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-205') as 'BCOP-205(D)',
      sum(case when scode = 'BCOP-206' then status else 0 end) as 'BCOP-206(A)',
      (select sum(status) from msta where rollno = 777 and scode = 'BCOP-206') as 'BCOP-206(D)'
      
from msta
where rollno <> 777 and doa>=@tfdate and doa<=@ttdate and section='Nil' and semester='Sem-2'
group by rollno, name
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE