mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 11:32:03 +00:00
Add test 03213_denseRank_percentRank_alias
This commit is contained in:
parent
cb056cf3a5
commit
9811a2e71b
@ -0,0 +1,45 @@
|
||||
---- denseRank() ----
|
||||
0 0 0 1 1 1 1
|
||||
3 0 0 2 2 2 2
|
||||
1 0 1 3 3 3 3
|
||||
4 0 1 4 4 4 4
|
||||
2 0 2 5 5 5 5
|
||||
6 1 0 1 1 1 1
|
||||
9 1 0 2 2 2 2
|
||||
7 1 1 3 3 3 3
|
||||
5 1 2 4 4 4 4
|
||||
8 1 2 5 5 5 5
|
||||
12 2 0 1 1 1 1
|
||||
10 2 1 2 2 2 2
|
||||
13 2 1 3 3 3 3
|
||||
11 2 2 4 4 4 4
|
||||
14 2 2 5 5 5 5
|
||||
15 3 0 1 1 1 1
|
||||
18 3 0 2 2 2 2
|
||||
16 3 1 3 3 3 3
|
||||
19 3 1 4 4 4 4
|
||||
17 3 2 5 5 5 5
|
||||
21 4 0 1 1 1 1
|
||||
24 4 0 2 2 2 2
|
||||
22 4 1 3 3 3 3
|
||||
20 4 2 4 4 4 4
|
||||
23 4 2 5 5 5 5
|
||||
27 5 0 1 1 1 1
|
||||
25 5 1 2 2 2 2
|
||||
28 5 1 3 3 3 3
|
||||
26 5 2 4 4 4 4
|
||||
29 5 2 5 5 5 5
|
||||
30 6 0 1 1 1 1
|
||||
---- percentRank() ----
|
||||
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,0 +1,59 @@
|
||||
-- https://github.com/ClickHouse/ClickHouse/issues/67042
|
||||
-- Reference generated using percent_rank() and dense_rank()
|
||||
|
||||
-- From ClickHouse/tests/queries/0_stateless/01591_window_functions.sql (for deterministic query)
|
||||
SELECT '---- denseRank() ----';
|
||||
select number, p, o,
|
||||
count(*) over w,
|
||||
rank() over w,
|
||||
denseRank() over w,
|
||||
row_number() over w
|
||||
from (select number, intDiv(number, 5) p, mod(number, 3) o
|
||||
from numbers(31) order by o, number) t
|
||||
window w as (partition by p order by o, number)
|
||||
order by p, o, number
|
||||
settings max_block_size = 2;
|
||||
|
||||
-- Modifed from ClickHouse/tests/queries/0_stateless/01592_window_functions.sql (for deterministic query)
|
||||
SELECT '---- percentRank() ----';
|
||||
|
||||
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,
|
||||
percentRank() 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;
|
Loading…
Reference in New Issue
Block a user