我有价格表:
CREATE TABLE IF NOT EXISTS price (
id INTEGER PRIMARY KEY AUTOINCREMENT,
shop INTEGER NOT NULL,
product INTEGER NOT NULL,
delivery VARCHAR(100),
score REAL,
opinions INTEGER,
avaiable INTEGER,
price REAL,
time INTEGER NOT NULL,
FOREIGN KEY(shop) REFERENCES shop(id),
FOREIGN KEY(product) REFERENCES product(id),
FOREIGN KEY(time) REFERENCES time(id)
);
我需要显示价格,但顺序应该是评分从大到小,意见从大到小,但价格应该是相反的从小到大。
这不起作用:
select score, opinions, shop.name, price from price
left join shop on shop.id = price.shop
order by score asc, price desc;
在sqlite中是否可能?
我的数据如下:
4.5 | 3380 | abfoto.pl | 9199.0
5.0 | 1304 | cyfrowe.pl | 9299.0
5.0 | 744 | fotoforma.pl | 9399.0
5.0 | 199 | fotopanorama.pl | 9099.0
4.0 | 911 | empik.com | 9099.0
5.0 | 3847 | komputronik.pl | 9190.0
5.0 | 1053 | sferis.pl | 9199.0
5.0 | 578 | fotoplus.pl | 9199.0
5.0 | 24 | e-oko.pl | 9199.0
5.0 | 55 | foto-kolodziej.pl | 9299.0
5.0 | 164 | foto-szop.pl | 9299.0
5.0 | 47139 | allegro.pl | 9347.77
5.0 | 526 | fotosoft.pl | 9399.0
4.5 | 7129 | mall.pl | 9401.0
5.0 | 144 | fotostrada.pl | 9499.0
上面应该有 5.0|fotopanorama.pl|9099.0
.
1条答案
按热度按时间7eumitmz1#
顺序应该是从大到小打分,意见从大到小,但价格应该是从小到大相反。
我想你想要:
注意,自从
score
如果存储为字符串,则在排序之前将其转换为数字会更安全(因此+ 0
).