MySQL Forums
Forum List  »  Newbie

How to summarize the count of some flag fields?
Posted by: Giulio Buccini
Date: October 16, 2010 12:39PM

Hello,

I'm going crazy with a simple task: I want to produce a query reporting how many rows in my "reports" table have two "flag" fields set to 'Y'.
For example, I have following "reports" table:

+----+------------------------+------+-------------+
| id | .....some fields...... |safety|functionality|
+----+------------------------+------+-------------+
| 1 | ...................... | Y | N |
| 1 | ...................... | Y | Y |
| 1 | ...................... | N | Y |
| 1 | ...................... | Y | N |
+----+------------------------+------+-------------+

so my query should produce something like:

+---------------+-------+
| flag | count |
+---------------+-------+
| safety | 3 |
| functionality | 2 |
+---------------+-------+

I have found a simple solution by chaining two SELECT statements through the UNION (and using only the COUNT() istruction).
But I'm using a php tool (not builded by me) that is translating my queries. This tools doesn't accept the UNION statement (!). So I must do what above using a single SELECT statement... how I can I do it?



Edited 1 time(s). Last edit at 10/16/2010 12:39PM by Giulio Buccini.

Options: ReplyQuote


Subject
Written By
Posted
How to summarize the count of some flag fields?
October 16, 2010 12:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.