Pau
Pau

Reputation: 31

MySQL - How to get total number of matches within a column

I tried this code:

SELECT SUM(bookingstatus)
FROM beo_eventorder AS TotalBookingStatu
WHERE bookingstatus = 'Tentative';

But this returns 0. There are 6 matches in the table. Why does this not return 6?

Screenshot of column:

Screenshot of column:

Upvotes: 0

Views: 45

Answers (2)

mendez7
mendez7

Reputation: 195

SUM adds all the elements on the column, in your case, it added all the strings to be 0. You should use a COUNT function instead.

Upvotes: 0

Harsh
Harsh

Reputation: 1319

You should use count instead of sum:

SELECT count(bookingstatus) FROM beo_eventorder AS TotalBookingStatus WHERE bookingstatus = 'Tentative';

Upvotes: 1

Related Questions