
聚集函数
select string_agg(c_name,',') as name from customer group by c_phone;
select c_custkey,group_concat(c_name order by c_name desc ) from customer group by c_custkey;聚集函数 + 过滤
select string_agg(c_name,',') filter (where c_name like 'ABC%') as name from customer group by c_phone;
select count(1) filter (where c_name like 'ABC%') from customer group by c_phone;窗口函数
select *, row_number() over (partition by o_custkey order by o_orderkey desc) as rank from orders where o_orderdate = '2022-01-01';
select string_agg(c_name,',') over (partition by c_phone) as name from customer;
-- rows/range
select string_agg(c_name,',') filter (where c_name like 'ABC%') over(partition by c_phone order by c_name ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) as name from customer;
-- exclude
select string_agg(c_name,',') over(partition by c_phone order by c_name ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE TIES) as name
from customer;窗口函数 + 过滤
select string_agg(c_name,',') filter (where c_name like 'ABC%') over(partition by c_phone) as name from customer;
select *, row_number() filter (where c_name like 'ABC%') over (partition by o_custkey order by o_orderkey desc) as rank from orders where o_orderdate = '2022-01-01';WITHIN函数
select string_agg(c_name,',') within group(order by c_custkey) over(partition by c_phone) name from customer;
SELECT percentile_cont(0.5) WITHIN GROUP (ORDER BY o.o_totalprice) FROM orders o group by o_custkey;支持表函数
SELECT * FROM generate_series(1, 10 ) AS t (n);
SELECT * FROM customer c, (VALUES( 1 ,2), (3, 4)) AS t(a, b)
WHERE t.a = c.c_current_addr_sk AND c.c_customer_sk > t.b;PawSQL识别两种语法解析错误,并在结果中提示用户,以便用户修正自己的SQL。



PawSQL专注数据库性能优化的自动化和智能化,支持MySQL,PostgreSQL,Opengauss等,提供的SQL优化产品包括。