1 (edited by lubos 2016-01-26 11:22:57)

Topic: Random select in DB

Hi!

I have table where is columns ID and PRICE. Then I have value MAXSUM.
Its possible to select random rows from table if I want SUM(PRICE) of selected rows is <= MAXSUM?

Thanks

Lubos

EDIT:

something like this:
select dattt  from data group by dattt having SUM(dattt) < 1  ---- but this query return more rows than SUM <1

Re: Random select in DB

Hello


try this:

SELECT SUM(dattt) FROM data GROUP BY dattt HAVING SUM(dattt) < 5 ORDER BY RANDOM()

where 5 is MAXSUM

Dmitry.

Re: Random select in DB

Dmitry,
no working. Still return more rows.....

Re: Random select in DB

Don't know how to do it using just SQL query, it's will be easy using SQL and some script.

Dmitry.

Re: Random select in DB

What about this?:

http://blog.rodolfocarvalho.net/2012/05 … qlite.html