473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Query that counts multiple values

Hi,
I have a very basic question but I havent found answer to it anywhere.

I have a table that has following columns: date, answer1, answer2,
answer3, answer4
and entry: 2007-1-1, 'a', 'b', 'a', 'c'

What I want to do is count number of character "a":s as an answer.
Normally (if using COUNT, MATCH..AGAINST) mysql returns rows it finds.
I want to find out how many times this character "a" appears in a
record.
What to do? Thanks for helping.

Br,
Sam

Feb 9 '07 #1
2 3431
On 9 Feb, 13:31, "LittleSam" <ss_d...@luukku.comwrote:
Hi,
I have a very basic question but I havent found answer to it anywhere.

I have a table that has following columns: date, answer1, answer2,
answer3, answer4
and entry: 2007-1-1, 'a', 'b', 'a', 'c'

What I want to do is count number of character "a":s as an answer.
Normally (if using COUNT, MATCH..AGAINST) mysql returns rows it finds.
I want to find out how many times this character "a" appears in a
record.
What to do? Thanks for helping.

Br,
Sam
revise your structure

date, answer, result

2007-01-01,1,'a'
etc

select count(*) from table where result = 'a' group by date.

or, if you really must use your existing structure, just join the
table to itself 3 times - but the first option is a better solution.

Feb 9 '07 #2
On 9 helmi, 15:54, "strawberry" <zac.ca...@gmail.comwrote:
On 9 Feb, 13:31, "LittleSam" <ss_d...@luukku.comwrote:
Hi,
I have a very basic question but I havent found answer to it anywhere.
I have a table that has following columns: date, answer1, answer2,
answer3, answer4
and entry: 2007-1-1, 'a', 'b', 'a', 'c'
What I want to do is count number of character "a":s as an answer.
Normally (if using COUNT, MATCH..AGAINST) mysql returns rows it finds.
I want to find out how many times this character "a" appears in a
record.
What to do? Thanks for helping.
Br,
Sam

revise your structure

date, answer, result

2007-01-01,1,'a'
etc

select count(*) from table where result = 'a' group by date.

or, if you really must use your existing structure, just join the
table to itself 3 times - but the first option is a better solution.
Thanks a lot for your advise!
I restructured my tables and now everything works as should.
Thanks again.

-Sam

Feb 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Spark | last post by:
Hi, Situation: Need a query to return number of ticket records by month of open in a log table where the ticket open record is older than 24 hours then the ticket pending or ticket closed...
7
by: jane | last post by:
HI, I was ask to do a query to get the member active condition I had table to show the member number and active status in three month. ACC A1 A2 A3 ---- -----------...
3
by: simon | last post by:
Hi I have a SQL query that counts values in a table and totals them up and works out a percentage, it involves a few counts, is there a better why to acheive what I want other than the way I...
10
by: Raj | last post by:
I have an MDC index on Big_A.Dt column. The following query always goes for a table scan. SELECT Key, Cd, Dt, SUM(Big_A ) FROM ( SELECT Big_A.Key , small_3.Cd,
1
by: sbowman | last post by:
I'm in the process of creating a monthly reporting database. I've worked out all the queries which are all counts of particular field values. I need to store these values in a table for historical...
3
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
I am somewhat new to Access and have been tasked with creating a reporting database for my operation. The problem I am having is that I am needing to use the Count function to calculate total...
8
by: Tetelestai | last post by:
I would like three counts in one query based on differing criteria. Each count is counting the same items. The difference between the items being counted is the characteristics (eg like to short). ...
5
by: Nobby | last post by:
On a crosstab query, I often produce reports that show Counts of values. the problem that I have is that where there are no counts, no values are returned i.e. there are blank cells. Is there an...
1
by: mskapek | last post by:
I need some advise on how to best create an Access 2002 report from multiple "total" queries, each which result in 3- 5 values that I need displayed on my report. Most of the queries do simple...
9
by: ncyankeefan | last post by:
I am trying to get the number of specific alerts for each month of the year. I would like to get these counts in one query or subquery. There is a date field in table so I can specifically get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.