标签:alias ble tin strong user 意思 ali column split
-- 求每个用户的拥有的产品数,其中userid需要简单split出来
SELECT
split (id, ‘-‘) [ 0 ] AS userid,
count(DISTINCT productid) AS productid
FROM
user_product
WHERE
dt >= ‘2018-05-01‘
GROUP BY
userid
你是不是想这样用?
看看报错
Invalid table alias or column reference ‘userid‘: (possible column names are: id, productid)
什么意思,意思是where和group by是先执行,然后才有select,所以group by的只能是已from的表字段或计算的字段。
如何修改,有很多方法,看方不方便:
【sql小坑】在group by里用select字段的别名?
标签:alias ble tin strong user 意思 ali column split
原文地址:https://www.cnblogs.com/everda/p/9111920.html