clickhouse SQLjoin语句

https://blog.csdn.net/vagabond6/article/details/79556968

clickhouse语法和mysql有些不同,需要额外注意写。如最常用的join,clickhouse要加别名(alias),using替换on,any left join替换join等。

mysql写法:

select city,star_sign,uid,ceil,height,weight,aht,awt from
 
(select uid,ceil,city,star_sign,height,weight from user_pro) t1
 
join
 
(select city,star_sign,avg(height) aht,avg(weight) awt from user_pro group by city,star_sign) t2
 
on t1.city = t2.city and t1.star_sign = t2.star_sign;

clickhouse写法:

select city,star_sign,uid,ceil,height,weight,aht,awt from
 
(select uid,ceil,city,star_sign,height,weight from user_pro)
 
any left join
 
(select city,star_sign,avg(height) AS aht,avg(weight) AS awt from user_pro group by city,star_sign)
 
using (city,star_sign);
 

你可能感兴趣的:(Clickhouse)