Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select a row with more than count func

Author  Topic 

younas02
Starting Member

28 Posts

Posted - 2012-06-28 : 10:06:39
hi.
i want to select rows with count function.
i want to select name, fathername, count(marks) with a condition like percentage >50, count(status) with a condition like pass or fail
is it possible ?
plzz help me

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2012-06-28 : 10:15:20
Dude - please don't cross post. You only need one post on this entire site - not one in each forum:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176267
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176266
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176265
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176263
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176262
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176261

Be One with the Optimizer
TG
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-06-28 : 10:17:45
quote:
Originally posted by younas02

hi.
i want to select rows with count function.
i want to select name, fathername, count(marks) with a condition like percentage >50, count(status) with a condition like pass or fail
is it possible ?
plzz help me



Younas,

Poste more explaination and some code you have tried to help us help you.

luck,

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

younas02
Starting Member

28 Posts

Posted - 2012-06-28 : 10:30:21
i have table of student tset results and i have to select name, father name , number of given test, number of pass results , number of fail results.
i have these columns and values
name , fathername , result
younas, inayat , pass
ali , hammed , fail
hamad ,nazeer , pass
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-06-28 : 11:01:52
quote:
Originally posted by younas02

i have table of student tset results and i have to select name, father name , number of given test, number of pass results , number of fail results.
i have these columns and values
name , fathername , result
younas, inayat , pass
ali , hammed , fail
hamad ,nazeer , pass



give an example of of marks (grades) and results you want.

What is your question?


--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-28 : 12:45:56
It sounds like you want the numbers for a test whereas the data you have given only allows the aggregates by a person taking multiple tests. In fact yoou have no way of not having duplicates (assuming a pearson can pass or fail more than one test).

select name, fathername, count(*), sum(case when result = 'pass' then 1 else 0 end), sum(case when result = 'fail' then 1 else 0 end)
from tbl
group by name, fathername

Hope you pass!

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

younas02
Starting Member

28 Posts

Posted - 2012-07-02 : 05:11:37
thnx alot dear it works for me.
thnx thnx
Go to Top of Page
   

- Advertisement -