Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create 'buckets' to count fields longer than certain length

Status
Not open for further replies.

elsenorjose

Technical User
Oct 29, 2003
684
0
0
US
I have a table with, among other fields, a field with media file names. I want to create a query that would allow me to create 'buckets' which count how many records exceed a certain length. This is what my output would theoretically look like:

Code:
length     count
50         100
100        50
1000       30

Using MySQL 5.0.27 on Windows XP SP2

Thank you.
 
I'm sure Rudy will come up with an elegant solution but how about something like
Code:
SELECT 50 AS length
     , SUM( CASE WHEN LENGTH(mediafn)>50 THEN 1 ELSE 0 END ) AS count
  FROM table

UNION

SELECT 100 AS length
     , SUM( CASE WHEN LENGTH(mediafn)>100 THEN 1 ELSE 0 END ) AS count
  FROM table

UNION

SELECT 1000 AS length
     , SUM( CASE WHEN LENGTH(mediafn)>1000 THEN 1 ELSE 0 END ) AS count
FROM table




Andrew
Hampshire, UK
 
Any performance issues I should be concerned about on a table with ~65 million rows? It's on a machine with a dual core 3Ghz CPU with 3GB of RAM. MySQL is pretty much all that's running on there but I'm still wondering if the query would run really slowly.

Thank you both for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top