Reputation: 737
I'm developing an ASP.NET web application using Visual Studio 2010 professional and a SQL Server database. I have some records in the database for the next tables:
Is there a way to calculate for example with only one query, how many records in table sarcini has stare_task (means task_state) = closed according to each employee(angajat) foreign key in sarcini? I think this is too ambigous but I don't know how to explain exactly what I mean.
Upvotes: 1
Views: 307
Reputation: 635
Select
id_angajat
,sum(case when stare_task = 'Closed' then 1 else 0 end) as [Closed_Records]
From sarcini
Group by id_angajat
Assuming MS SQL Server and that you are just using table sarcini..
Edit: Sql Fiddle example: http://sqlfiddle.com/#!3/c2c89/2
Upvotes: 2