Jump to content

[SOLVED] Need help determining most frequent number in a field


Craig79

Recommended Posts

Thanks Gamic,

 

I've never seen a query like that! I tried it but I couldn't get it to work. Here's what I did:

 

$SQL = "select * from(select my_state, count(*) as countOfUse from t_locations group by my_price)

tmp order by tmp.countOfUse desc";

 

The "my_state" field in the "t_locations" table consists of integers. These integers stand for USA state codes.  The "my_price" field is in the same table and it also consists of integers (dollar values rounded up). I'm passing in the state code from a PHP script to find the most commonly paid price for that state (but not the average). So, the puzzle is to find the most commonly paid price where the state code = 65.

 

Could you please clarify the query?

Thank you!

Link to comment
Share on other sites

<?php
$SQL = "
select * from(
select 
	my_state, 
	count(*) as countOfUse 
from t_locations 
group by my_state
)tmp 
order by tmp.countOfUse desc";
?>

 

This query tells you how many times a value of my_state appears in t_locations.

 

To get the most commonly paid price for a state you would do something similar.

selet * from(
select
	my_price,
	count(*) as countOfUse
from t_locations
where my_state = 65
group by my_price
)tmp order by tmp.countOfUse desc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.