Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Distinct and Aggregate Functions
Message
From
18/10/2000 18:19:57
 
 
To
18/10/2000 16:46:22
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00431161
Message ID:
00431222
Views:
8
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform