Need mysql query to get students PASS, FAIL and COUNT in single query -


i having table below:

id    studentname   marks  1        x           60  2        y           25  3        z           50 

here pass marks 50 , above

my output should be

id    studentname   marks  status  totalcount  1        x           60     pass       2  2        y           25     fail       1  3        z           50     pass       2 

here total count of pass 2 total number of fail 1.

how can done using mysql query.

thanks in advance....

select a.id,a.studentname,a.marks,b.status,b.totalstatus students a,     (select count(1) totalstatus,if(marks>=50,'pass','fail') status         students group if(marks>=50,'pass','fail')) b b.status = if(a.marks>=50,'pass','fail'); 

this works !!! tried !!!

lwdba@localhost (db test2) :: create table students
-> (
-> id int not null,
-> studentname varchar(10),
-> marks int not null,
-> primary key (id)
-> );
query ok, 0 rows affected (0.17 sec)

lwdba@localhost (db test2) :: insert students values
-> (1,'x',60),
-> (2,'y',25),
-> (3,'x',50);
query ok, 3 rows affected (0.06 sec)
records: 3 duplicates: 0 warnings: 0

lwdba@localhost (db test2) :: select a.id,a.studentname,a.marks,b.status,b.totalstatus
-> students a,(select count(1) totalstatus,if(marks>=50,'pass','fail') status
from students group if(marks>=50,'pass','fail')) b
-> b.status = if(a.marks>=50,'pass','fail');
+----+-------------+-------+--------+-------------+
| id | studentname | marks | status | totalstatus |
+----+-------------+-------+--------+-------------+
| 1 | x | 60 | pass | 2 |
| 2 | y | 25 | fail | 1 |
| 3 | x | 50 | pass | 2 |
+----+-------------+-------+--------+-------------+
3 rows in set (0.00 sec)

give try !!!


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -