0

When i checked it, it doesn't remove duplication of value. Why?

example) Group by a , Group by a,b,c

Is there a difference between Group by a, Group by a,b,c ?

I wrote SQL query like this ::

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country; 

result ::

Table: Customers

COUNT(CustomerID)   Country
---------------------------------
        3           Argentina        
        2           Austria
        2           Belgium
        9           Brazil
        3           Canada
        2           Denmark
        2           Finland

to

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country, CustomerID; 
Table: Customers

COUNT(CustomerID)   Country
---------------------------------
        1           Germany        
        1           Mexico
        1           Mexico
        1           UK
        1           Sweden
        1           Germany
        1           France

Why doesn't tie same value changed query from Column_name? It display all value along column_name. I wonder if it works. thank you.

Quack
  • 680
  • 1
  • 8
  • 22
  • 1
    what do you want to receive in the output? – mangusta Apr 29 '19 at 02:01
  • Your last paragraph is unintelligible. Use enough words, sentences & references to parts of examples to clearly & fully say what you mean. When describing a result: Say enough that someone could go away & come back with a solution. Please in code questions give a [mcve]--cut & paste & runnable code & desired output & clear specification & explanation. PS w3s is not a good resource, find a textbook or DMBS manual. – philipxy Apr 29 '19 at 02:23
  • Please [use text, not images/links, for text--including tables & ERDs.](https://meta.stackoverflow.com/q/285551/3404097) Paraphrase or quote from other text. Use images only for what cannot be expressed as text or to augment text. Images cannot be searched for or cut & pasted. Include a legend/key & explanation with an image. Make your post self-contained. Insert images/links using edit functions. – philipxy Apr 29 '19 at 02:35
  • (Obviously) This is a faq. Before considering posting please always google your error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. – philipxy Apr 29 '19 at 02:49
  • 1
    Possible duplicate of [Using group by on multiple columns](https://stackoverflow.com/q/2421388/3404097) – philipxy Apr 29 '19 at 02:51
  • 1
    PS After you group by country & id, country-id pairs are unique & each pair has a group of rows for aggregation. When you select country you get the country from each country-id row. If there is more than one id per country then some country-id rows have the same country. So you get duplicate countries. And each count for a selected country is for the group of rows belonging to the country-id row that the country came from. *Read the description of how group by works.* – philipxy Apr 29 '19 at 02:52
  • If the duplicate link or another question or my comment give you an answer, you will prevent more downvotes if you delete this. But you can maybe reduce downvotes or maybe get upvotes if you edit this to be clear, researched & prepared, per my comments. But if you are trying to ask what I guess you are trying to ask then it is a duplicate & should still be closed & some people may still downvote because it is a duplicate & so it is 'not useful' & 'not researched'. – philipxy Apr 29 '19 at 03:41
  • @philipxy It changed. Sorry. I won't ever do it again thank you. – Quack Apr 29 '19 at 04:13
  • @mangusta I expect to aggregate value such a Group – Quack Apr 29 '19 at 04:14
  • You typically GROUP BY the same columns as you SELECT, except those who are arguments to set functions. – jarlh Apr 29 '19 at 06:47
  • @jarlh thank you!! I'm fully aware of what was said on Group by multiple !! – Quack Apr 29 '19 at 07:29

0 Answers0