Solved

Count entries in enum field

Posted on 2007-04-03
2
450 Views
Last Modified: 2008-01-09
I have entered survey data into a MySQL database. I have built reports to process much of the data, but I'm stuck on the best way to handle some enum fields.

I have four fields called Type1, Type2, Type3, Type4.
Type1 has the values "Full-time" & "Part-time"
Type 2 has "Solo" & "Group"
and so on.

I want to do a count query to return a report to tell me how many responded Full-time, Part-Time, Solo, Group, and so on for each option of each enum field.

I know I can do a separate query for each option of each field, but there has to be a more efficient way.
0
Comment
Question by:RKFcomputers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 18843876
You can do it in one way, but if it is faster, I dont know. Its done like:
select
  count(if(Type1='Full-time', 1, null)) as FullTime,
  count(if(Type1='Part-time', 1, null)) as PartTime,
 ...
FROM Table
0
 

Author Comment

by:RKFcomputers
ID: 18844686
Thanks ... that's doing the trick.
0

Featured Post

Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question