General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
> sum(quantity)*sum(price)/sum(quantity)
I'd say you need sum(quantity*price)/sum(quantity) for the average price, or simply avg(price).
sum(quantity)*sum(price)/sum(quantity) is definately equal to sum(price), which is not the avarage price.
For your main question: You need a third select if the second one has no result, I don't see a way to put it inside a single SQL select.
The question is, do you want to take nearest date after m.ldend or nearest before m.ldfirst
or nearest to any of those two dates?
Bye, Olaf.
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