update tests

This commit is contained in:
lgbo-ustc 2024-08-03 06:14:52 +08:00
parent 2e521e17ed
commit 682c735fa6
4 changed files with 75 additions and 54 deletions

View File

@ -79,27 +79,3 @@ iPhone 900 Smartphone 500 500
Kindle Fire 150 Tablet 150 350
Samsung Galaxy Tab 200 Tablet 175 350
iPad 700 Tablet 350 350
---- Q8 ----
Lenovo Thinkpad Laptop 700 1 0
Sony VAIO Laptop 700 1 0
Dell Vostro Laptop 800 3 0.6666666666666666
HP Elite Laptop 1200 4 1
Microsoft Lumia Smartphone 200 1 0
HTC One Smartphone 400 2 0.3333333333333333
Nexus Smartphone 500 3 0.6666666666666666
iPhone Smartphone 900 4 1
Kindle Fire Tablet 150 1 0
Samsung Galaxy Tab Tablet 200 2 0.5
iPad Tablet 700 3 1
Others Unknow 200 1 0
---- Q9 ----
0 1 0
1 2 1
2 3 2
3 4 3
4 5 4
5 6 5
6 7 6
7 8 7
8 9 8
9 10 9

View File

@ -101,37 +101,7 @@ SELECT
FROM products INNER JOIN product_groups USING (group_id)) t
order by group_name, product_name, price;
select '---- Q8 ----';
INSERT INTO product_groups VALUES (4, 'Unknow');
INSERT INTO products (product_id,product_name, group_id,price) VALUES (12, 'Others', 4, 200);
SELECT *
FROM
(
SELECT
product_name,
group_name,
price,
rank() OVER (PARTITION BY group_name ORDER BY price ASC) AS rank,
percent_rank() OVER (PARTITION BY group_name ORDER BY price ASC) AS percent
FROM products
INNER JOIN product_groups USING (group_id)
) AS t
ORDER BY
group_name ASC,
price ASC,
product_name ASC;
drop table product_groups;
drop table products;
select '---- Q9 ----';
select number, row_number, cast(percent_rank * 10000 as Int32) as percent_rank
from (
select number, row_number() over () as row_number, percent_rank() over (order by number) as percent_rank
from numbers(10000)
order by number
limit 10
)
settings max_block_size=100;

View File

@ -0,0 +1,22 @@
Lenovo Thinkpad Laptop 700 1 0
Sony VAIO Laptop 700 1 0
Dell Vostro Laptop 800 3 0.6666666666666666
HP Elite Laptop 1200 4 1
Microsoft Lumia Smartphone 200 1 0
HTC One Smartphone 400 2 0.3333333333333333
Nexus Smartphone 500 3 0.6666666666666666
iPhone Smartphone 900 4 1
Kindle Fire Tablet 150 1 0
Samsung Galaxy Tab Tablet 200 2 0.5
iPad Tablet 700 3 1
Others Unknow 200 1 0
0 1 0
1 2 1
2 3 2
3 4 3
4 5 4
5 6 5
6 7 6
7 8 7
8 9 8
9 10 9

View File

@ -0,0 +1,53 @@
set allow_experimental_analyzer=1;
drop table if exists product_groups;
drop table if exists products;
CREATE TABLE product_groups (
group_id Int64,
group_name String
) Engine = Memory;
CREATE TABLE products (
product_id Int64,
product_name String,
price DECIMAL(11, 2),
group_id Int64
) Engine = Memory;
INSERT INTO product_groups VALUES (1, 'Smartphone'),(2, 'Laptop'),(3, 'Tablet');
INSERT INTO products (product_id,product_name, group_id,price) VALUES (1, 'Microsoft Lumia', 1, 200), (2, 'HTC One', 1, 400), (3, 'Nexus', 1, 500), (4, 'iPhone', 1, 900),(5, 'HP Elite', 2, 1200),(6, 'Lenovo Thinkpad', 2, 700),(7, 'Sony VAIO', 2, 700),(8, 'Dell Vostro', 2, 800),(9, 'iPad', 3, 700),(10, 'Kindle Fire', 3, 150),(11, 'Samsung Galaxy Tab', 3, 200);
INSERT INTO product_groups VALUES (4, 'Unknow');
INSERT INTO products (product_id,product_name, group_id,price) VALUES (12, 'Others', 4, 200);
SELECT *
FROM
(
SELECT
product_name,
group_name,
price,
rank() OVER (PARTITION BY group_name ORDER BY price ASC) AS rank,
percent_rank() OVER (PARTITION BY group_name ORDER BY price ASC) AS percent
FROM products
INNER JOIN product_groups USING (group_id)
) AS t
ORDER BY
group_name ASC,
price ASC,
product_name ASC;
drop table product_groups;
drop table products;
select number, row_number, cast(percent_rank * 10000 as Int32) as percent_rank
from (
select number, row_number() over () as row_number, percent_rank() over (order by number) as percent_rank
from numbers(10000)
order by number
limit 10
)
settings max_block_size=100;