Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Distinct and Aggregate Functions
Message
De
18/10/2000 18:19:57
 
 
À
18/10/2000 16:46:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00431161
Message ID:
00431222
Vues:
10
This may be somewhat out of line, but.........

Given a table like
Recip UnitSold
AA 1
AA 1
AA 2
AA 3
AA 3
BB 1
BB 2
BB 3
BB 3

Are you sure you want SELECT recipients,SUM(DIST unitsold) GROUP BY recipient???
Your query yields

AA 6
BB 6

Where the 6 comes from summing the distinct values (1,2,3)







>I have an view I've created which needs to perform SUM and AVG calculations on a number of fields. I only want to count each field once, so I'm using distinct - e.g.
>sele sum(distinct unitssold) from revenue group by recipient.
>
>My problem is that I want to calculate several fields with aggregate functions, but I get an error when I use DISTINCT more than once. For example, doing something like:
>sele sum(distinct unitssold),avg(distinct saleprice) from revenue group by ...
>
>This gives me an "SQL - Distinct" error.
>
>Can distinct only be used once in an SQL statement?
>
>Thanks,
>
>David
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform