mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-12-15 19:09:41 +00:00
ad79ef48a2
* add tests * add bench
145 lines
2.9 KiB
Plaintext
145 lines
2.9 KiB
Plaintext
|
|
CREATE TABLE fruits(
|
|
name TEXT COLLATE NOCASE,
|
|
color TEXT COLLATE NOCASE
|
|
);
|
|
|
|
|
|
INSERT INTO fruits (name, color) VALUES ('apple', 'RED');
|
|
INSERT INTO fruits (name, color) VALUES ('APPLE', 'yellow');
|
|
INSERT INTO fruits (name, color) VALUES ('pear', 'YELLOW');
|
|
INSERT INTO fruits (name, color) VALUES ('PEAR', 'green');
|
|
|
|
|
|
SELECT name, color, dense_rank() OVER (ORDER BY name) FROM fruits;
|
|
|
|
|
|
SELECT name, color,
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits;
|
|
|
|
|
|
SELECT name, color,
|
|
dense_rank() OVER (ORDER BY name),
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits;
|
|
|
|
|
|
SELECT name, color,
|
|
dense_rank() OVER (ORDER BY name),
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits ORDER BY color;
|
|
|
|
|
|
CREATE TABLE t1(a BLOB, b INTEGER, c COLLATE nocase);
|
|
INSERT INTO t1 VALUES(1, 2, 'abc');
|
|
INSERT INTO t1 VALUES(3, 4, 'ABC');
|
|
|
|
|
|
SELECT c=='Abc' FROM t1
|
|
|
|
|
|
SELECT c=='Abc', rank() OVER (ORDER BY b) FROM t1
|
|
|
|
|
|
SELECT b=='2' FROM t1
|
|
|
|
|
|
SELECT b=='2', rank() OVER (ORDER BY a) FROM t1
|
|
|
|
|
|
CREATE TABLE t1(a);
|
|
CREATE TABLE t2(a,b,c);
|
|
|
|
|
|
SELECT EXISTS(SELECT 1 FROM t1 ORDER BY sum(a) OVER ()) FROM t1;
|
|
|
|
|
|
SELECT sum(a) OVER () FROM t2
|
|
ORDER BY EXISTS(SELECT 1 FROM t2 ORDER BY sum(a) OVER ());
|
|
|
|
|
|
CREATE TABLE t1(a, b TEXT);
|
|
INSERT INTO t1 VALUES('A', 1), ('A', 2), ('2', 1), ('2', 2);
|
|
|
|
|
|
SELECT b, b=count(*), '1,2' FROM t1 GROUP BY b;
|
|
|
|
|
|
SELECT b, b=count(*), group_concat(b) OVER () FROM t1 GROUP BY b;
|
|
|
|
|
|
CREATE TABLE t1(a, b, c, d, e);
|
|
CREATE INDEX i1 ON t1(a, b, c, d, e);
|
|
|
|
|
|
CREATE TABLE t0(c0);
|
|
INSERT INTO t0(c0) VALUES (0);
|
|
|
|
|
|
SELECT * FROM t0 WHERE
|
|
EXISTS (
|
|
SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
|
|
) >=1 AND
|
|
EXISTS (
|
|
SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
|
|
) <=1;
|
|
|
|
|
|
SELECT * FROM t0 WHERE EXISTS (
|
|
SELECT MIN(c0) OVER (), CUME_DIST() OVER () FROM t0
|
|
)
|
|
BETWEEN 1 AND 1;
|
|
|
|
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(x, y);
|
|
INSERT INTO t1 VALUES(10, 1);
|
|
INSERT INTO t1 VALUES(20, 2);
|
|
INSERT INTO t1 VALUES(3, 3);
|
|
INSERT INTO t1 VALUES(2, 4);
|
|
INSERT INTO t1 VALUES(1, 5);
|
|
|
|
|
|
SELECT avg(x) OVER (ORDER BY y) AS z FROM t1 ORDER BY z
|
|
|
|
|
|
SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY (z IS y);
|
|
|
|
|
|
SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY (y IS z);
|
|
|
|
|
|
SELECT avg(x) OVER (ORDER BY y) z FROM t1 ORDER BY z + 0.0;
|
|
|
|
|
|
CREATE TABLE t1(a, b);
|
|
INSERT INTO t1 VALUES(1, 2), (3, 4);
|
|
SELECT min( sum(a) ) OVER () FROM t1;
|
|
|
|
|
|
SELECT min( sum(a) ) OVER () FROM t1 GROUP BY a;
|
|
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT 0 AS x
|
|
UNION
|
|
SELECT count() OVER() FROM (SELECT 0)
|
|
ORDER BY 1
|
|
;
|
|
|
|
|
|
SELECT(
|
|
SELECT x UNION
|
|
SELECT sum( avg((SELECT x FROM v1)) ) OVER()
|
|
)
|
|
FROM v1;
|
|
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
INSERT INTO t1 VALUES(NULL,'bb',356);
|
|
INSERT INTO t1 VALUES('CB','aa',158);
|
|
INSERT INTO t1 VALUES('BB','aa',399);
|
|
INSERT INTO t1 VALUES('FF','bb',938);
|
|
|