General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only