473,385 Members | 1,730 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,385 software developers and data experts.

How to count frequen data in database

hii..
i got a really have kinda complicated problem.

this is my table

table participate
| id |phone_no|vote1|vote2|vote3 |vote4|vote5|status|
|_1_| +012++_|_1__|__3__|__4__|__5_|___4_|__5_|
cont another data..

the situation is like this, i already got the most frequent data that had been inserted from vote1 to vote 5,and the result is 4example.

now comes the problems,

i need to detect the phone_no(can be repeated on the same field) that had the biggest data with values 4 on vote1 to vote 5. with rules that the status must be 5 or the vote will not be count.

please help me.. i've been stuck here about a weeks.
pls4xx...
Aug 13 '09 #1
3 2467
SLauren
60
If you already have the result, then the following query might help:

Expand|Select|Wrap|Line Numbers
  1. SELECT phone_no FROM Participate WHERE status = 5 and result IN (GREATEST(vote1,vote2,vote3,vote4,vote5));
Hope this could help.

Thanks,
Lauren
Aug 13 '09 #2
thank you so much for reply..

i'm so sorry, this is my bad.
what i want is to retrieve the phone no that has a most frequent value 4 in vote1 to vote5. and how much it had it.

please help me..
Aug 13 '09 #3
SLauren
60
Can you add one more column to your table, say "occurrence" with a default value of zero.
If you already have the result with you, then you can try the following query which will update your occurrence column and get the phone number which will have maximum number of occurrences for the result:

Expand|Select|Wrap|Line Numbers
  1. UPDATE participate SET occurrence = IF(vote1 <=  result,vote1 div result,0) + if(vote2 <=  result,vote2 div result,0) + if(vote3 <= result,vote3 div result,0) + if(vote4 <= result,vote4 div result,0) + if(vote5 <= result,vote5 div result,0);
// Declare an <int> variable to hold the maximum count for the result, say "maxOccurrences".

Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(occurrence)  INTO maxOccurrences from Participate;
  2. SELECT phone_no FROM Participate WHERE status = 5 AND occurrence = maxOccurrences;
Hope this could help.
Thanks,
Lauren
Aug 14 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pete | last post by:
Okay, I'm still stuck with this problem. Here's a quick recap/summary :- 1. Page 1:User checks 3 out of 10 checkboxes and submits form to page 2 2. Page 2:Item count shows 3 items. User checks...
0
by: Ireneus Broncel | last post by:
I have a class which reads Groups and Users from ActiveDirectory. The Problem is, that i have about 10000 rows as product. When I am trying to read the "memberOf" Objects out of this field i get...
6
by: Kulwinder Sayal | last post by:
Hi In ASP it was so simple to get the no. of records using RecordCount. Can anyone help me how to write the no. of records my sqlquery has searched Thanks Kulwinder
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
1
by: danibecr | last post by:
I'm trying to make a table that will daily count the records imported and save them to a seperate table along with the date imported. But as of now after all the processing is complete I delete...
3
by: Margie | last post by:
Hello all, after getting no where with my Access 2007 database problem for an entire week I figured I could use some outside help. Wanting to skill myself in Access, I decided to make a movie...
12
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want...
8
by: Gilles Ganault | last post by:
Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.