Retrieving Results based on distinct and grouped

Posted on 2011-10-09
Last Modified: 2012-05-12

I have a table with data that is broken down as follows:

countryCode, cityCode, storeCode, storeType, gridCodeX

I need to get a result, distinct, from this table so it totals up how many distinct gridCodeX's there are in a store within a city within a country

I have tried the following in around 100 itterations but to no avail!

Any help would be much appreciated.



select distinct countrycode,citycode,storecode,count(gridcodex) from block 
group by countrycode,citycode,storecode, gridCodeX

Open in new window

Question by:kenuk110
    LVL 15

    Accepted Solution

    select countrycode,citycode,storecode,count( distinct  gridcodex) from block
    group by countrycode,citycode,storecode, gridCodeX

    Author Comment

    Perfect, looks so simple when you see the answer yet seems impossible when you don't.

    Really appreciate you help.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now