Reputation: 1774
I have project table in following format:
And, I need to have MYSQL that can give me data in following format:
Basically, I have to group the data based on location. Then have to count the successful and unsuccessful projects. "Successful" column has total count of projects for which percentageRaised is more than or equal to 1 and Unsuccessful column has total count of project for which percetageRaised in less than 1.
I just have basic understanding of mysql. Need your advise.
Upvotes: 0
Views: 234
Reputation: 263933
MySQL Supports boolean arithmetic.
SELECT Location,
SUM(percentageRaised > 0) successful,
SUM(percentageRaised < 0) unsuccessful,
FROM tableName
GROUP BY Location
Upvotes: 0
Reputation: 238296
select location
, sum(case when PercentageRaised >= 1.0 then 1 end) as successful
, sum(case when PercentageRaised < 1.0 then 1 end) as unsuccessful
from YourTable
group by
location
Upvotes: 2