MySQL get sum of selected records
I have a table of store items with their price. I'm trying to write a mysql query that pulls a number of items (between 3 and 6) at random, with the TOTAL value of all items within $20 of a value chosen by the user. Here is what I have so far...
SELECT item,price,sum(price)
FROM items
WHERE sum(price) BETWEEN ($value-10) AND ($value+10)
ORDER BY rand() LIMIT $randomValue
Obviously, my issue is that sum(price) takes the sum of ALL items in the table as opposed to the records selected. I'm sort of hit a wall, can anyone help me with this query?
Subject
Written By
Posted
MySQL get sum of selected records
October 23, 2014 02:34AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.