Solved

MySQL query question - count(*)

Posted on 2012-03-14
1
375 Views
Last Modified: 2012-03-14
At the moment I'm using this query to count distinct cities with more than 2 businesses.

SELECT DISTINCT bizCity, COUNT(*) as biz_count FROM finance WHERE bizState='$bizState'  GROUP BY bizCity HAVING biz_count > 2

What I would like to do is to select all distinct cities with 100-200 businesses or with 200-300. What is the query in this case?

Thank you
0
Comment
Question by:seopti
1 Comment
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
Comment Utility
DISTINCT is not required as you are already grouping the records.
You can try like this.

SELECT bizCity, COUNT(*) as biz_count FROM finance WHERE bizState='$bizState'  GROUP BY bizCity HAVING COUNT(*) between 100 and 200

SELECT bizCity, COUNT(*) as biz_count FROM finance WHERE bizState='$bizState'  GROUP BY bizCity HAVING COUNT(*) between 200 and 300
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now