Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group by clause
Message
De
16/03/2007 19:39:58
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
01204878
Message ID:
01204885
Vues:
21
>>I am trying to understand what the Group by clause in an SQL select statement does. Can someone explain this in simple terms?
>>
>>Thanks
>
>It GROUP all similar records into one.
>Imagine you have that data:
>
>Fld1         Fld2              Fld3
>-------------------------------------
>1              2                3
>1              2                3
>1              2                3
>1              2                4
>1              2                5
>
>And you issue the following SQL SELECT
>
>SELECT Fld1, Fld2, Fld3;
>       FROM MyTable
>       GROUP BY Fld1, Fld2, Fld3
>
>You will get the following result:
>
>
>Fld1         Fld2              Fld3
>-------------------------------------
>1              2                3
>1              2                4
>1              2                5
>
>
>But if you want this:
>
>SELECT Fld1, Fld2, SUM(Fld3) AS Fld3;
>       FROM MyTable
>       GROUP BY Fld1, Fld2
>
>
>You will get:
>
>Fld1         Fld2              Fld3
>-------------------------------------
>1              2                18
>
Based on your and Freds response, it appears Group by is primarially usefull when there is a summation of som sort involved. Would you agree? It appears that if there are fields in the select that cannot be summed there is an error. Such as SELECT * FROM ORDERS GROUP BY DATE. I think I am having difficulty because I think of it as a group in the report designer.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform