How to mix ASC and RANDOM() on SQLite ORDER BY -


so, i'm facing error while trying use order 2 columns:

... order val, random();

error is: "2nd order term not match column in result set"

i tried different ways combine asc sorting 1st column , random sorting second column, no luck.

updated provide more info

create table tabela ( id integer, val text, primary key(id) );

insert tabela (val) values ('paid'); insert tabela (val) values ('paid'); insert tabela (val) values ('paid'); insert tabela (val) values ('standard'); insert tabela (val) values ('standard'); insert tabela (val) values ('standard'); insert tabela (val) values ('standard'); insert tabela (val) values ('standard'); 

expected sample result:

val        id ---        --- paid       3 paid       1 paid       2 standard   5 standard   8 standard   4 standard   6 standard   7 

where 'id' 1,2,3 randomly sorted within 'paid' 'val' , 'id' 4 ... 8 randomly sorted within 'standard' 'val'

select val, id (select random() r, * tabela) order val, r;

the trick make on-the-fly table (inside (...)) has column random values. possible order that.
note query sorting/ordering complete rows of on-the-fly table.

output 1:

paid|1   paid|3   paid|2   standard|8   standard|5   standard|7   standard|6   standard|4   

output 2:

paid|3   paid|1   paid|2   standard|5   standard|8   standard|7   standard|4   standard|6   

please excuse impression think of ordering columns. might see difference, if use subquery in (...), study output , imagine "manually" sorting rows, while not being allowed change of rows.

this query making on-the-fly table (with additional ordering):

select random() r, * tabela order val, id;   

and output:

6112298175921944810|1|paid   -750320757383183987|2|paid   -4687754812847362857|3|paid   574487853771424670|4|standard   6662074554381494613|5|standard   5947282373212186891|6|standard   -695595223160523440|7|standard   -6914056362765123037|8|standard 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -