- sqlite不是不支持
RANK
。
- 您必须有四个不同的查询
UNION
。
因此,以下查询将返回所需的行:
SELECT * FROM product_achievement ORDER BY value LIMIT 3
UNION
SELECT * FROM product_achievement ORDER BY value DESC LIMIT 3
UNION
SELECT * FROM product_achievement ORDER BY volume LIMIT 3
UNION
SELECT * FROM product_achievement ORDER BY volume DESC LIMIT 3;
解决方法RANK
:
如果您还需要排名信息,我建议创建一个VIEW
with 排名:
CREATE VIEW ranked_product_achievement AS
SELECT *,
(SELECT COUNT() FROM product_achievement WHERE value<=t.value) AS r_value_a,
(SELECT COUNT() FROM product_achievement WHERE value>=t.value) AS r_value_d,
(SELECT COUNT() FROM product_achievement WHERE volume<=t.volume) AS r_volume_a,
(SELECT COUNT() FROM product_achievement WHERE volume>=t.volume) AS r_volume_d
FROM product_achievement AS t;
然后你可以SELECT
从创建的视图中:
SELECT id, category, value, volume, r_value_a, r_volume_a
FROM ranked_product_achievement
WHERE r_value_a<=3 OR r_value_d<=3 OR r_volume_a<=3 OR r_volume_d<=3;