Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MySQL query question - count(*)

Posted on 2012-03-14
1
Medium Priority
?
420 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 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 37722905
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

916 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