|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
conditions with COUNT
here's my current code:
Code:
SELECT projects.name,count(tasks.ID) As totalTasks FROM projects left join tasks on projects.id=tasks.projectID GROUP BY projects.ID What I want to do is modify this so that it returns a count of the open tasks (tasks.open = true) instead of all the tasks, but I'm not sure where to insert the condition. I tried: Code:
SELECT projects.name,count(tasks.ID) As openTasks FROM projects left join tasks on projects.id=tasks.projectID WHERE tasks.open=true GROUP BY projects.ID but this only returns rows where tasks.open = true instead of only counting where tasks.open= true. Can anybody help me out? |
|
#2
|
||||
|
||||
|
Code:
select projects.name
, count(tasks.ID) as totalTasks
, sum( case when tasks.open = true
then 1 else 0 end ) as opentasks
from projects
left
join tasks
on projects.id = tasks.projectID
group
by projects.name
rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > conditions with COUNT |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|