Bob Rea schrieb am Samstag, 21. Juli 2001, 19:14:34:

> On Friday 20 July 2001 10:46 pm, you wrote:
>> You may want to understand what distinct and avg means. The
>> combination doesn't make sense.

> I took the example in question out of a book that I am using to teach 
> myself SQL. So I don't quite understand what it is after. It says, 
> "The following example uses the AVG() function to return the average 
> product price offered by a specific vendor....here the DISTINCT 
> argument is used so that the average only takes into account unique 
> prices"

> Does this make sense at all? in MySQL?

Well, it came to me after my reply that this might be the meaning
of the query. Actually, I don't know if this is standard SLQ and
MySQL will support it or not. The error messages indicates it
does not, but I may be wrong.

Anyway, according to the example, it is clear that the average of
all prices may differ substantially from the average of all
distinct prices.  If the latter does make sense economically is
another question.

The usual prescription for things not implemented is to look for
a work around.  In this case, it would be very easy to create a
temporary table (could be a memory table which is very fast but
has some restrictions), write all distinct values to that table
and take an average from those.

> Thanks for helping a learner.


You are welcome.

>> Bob Rea schrieb am Samstag, 21. Juli 2001, 02:36:11:
>> > The SQL book I am using has this:
>>
>> mysql>> select avg(distinct prod_price) as avg_price
>>
>> >     -> from Products
>> >     -> where vend_id = 'dll01'
>> >     -> ;
>> >
>> > and responds thus:
>> > ERROR 1064: You have an error in your SQL syntax near 'distinct
>> > prod_price) as avg_price
>> > from Products
>> > where vend_id = 'dll01'' at line 1
>> >
>> > How do I do this, if I can?



-- 
Herzlich
Werner Stuerenburg            

_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.de



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to