RIAS
asked on
SQL Query having where clause in count
Hi,
I am trying to get count on a column with a condition.Any suggestion on how to use count having a where clause
example;
WHERE (C.RegistrationNumber is null or C.RegistrationNumber = '') and count the return value
Cheers
I am trying to get count on a column with a condition.Any suggestion on how to use count having a where clause
example;
WHERE (C.RegistrationNumber is null or C.RegistrationNumber = '') and count the return value
Cheers
ASKER
This query just returns 1,0 ,need to have sum of the returned records.
The query is
Return employees who have more than 1 car
Include a column that gives the number of cars they have registered
Cheers
The query is
Return employees who have more than 1 car
Include a column that gives the number of cars they have registered
Cheers
how's your data looks like and what's your expected output?
try:
select c.yourfield,
count(C.RegistrationNumber) yourCnt
from yourTable C
where C.RegistrationNumber is not null and C.RegistrationNumber <> ''
Group by c.yourfield
ASKER
Cheers mate wiil try and get back !
ASKER
This query is errored
select E.EmployeeID,E.Firstname
count(C.RegistrationNumber ) Number_of_Cars_Registered FROM
B35_Employees E INNER JOIN B35_Cars C
ON E.EmployeeID = C.EmployeeID
WHERE COALESCE(C.RegistrationNum ber, '') <> ''
Group by C.EmployeeID
select E.EmployeeID,E.Firstname
count(C.RegistrationNumber
B35_Employees E INNER JOIN B35_Cars C
ON E.EmployeeID = C.EmployeeID
WHERE COALESCE(C.RegistrationNum
Group by C.EmployeeID
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For example..
Select athlete, year, Sum(annual salary)
FROM league_stats
GROUP BY athlete, year
HAVING Sum(AnnualSalary) > 1000000 -- that made over a million bucks in their careers
Select athlete, year, Sum(annual salary)
FROM league_stats
GROUP BY athlete, year
HAVING Sum(AnnualSalary) > 1000000 -- that made over a million bucks in their careers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers Experts!
Open in new window