字符串的处理要求多样,这里做积累。
1. 首字母大写:
sql 没有像 python 一样,首字母大写的函数–title()
substring(name,2):左起第二个开始取子集
力扣1667:
select user_id,concat(upper(left(name,1)),lower(substring(name,2))) as name from Users order by user_id
2. 聚合合并:
一般地,group by 后被单值覆盖,group_concat(… [order by …]) 聚合后保留多值
力扣1484:
select sell_date,count(distinct product) as num_sold,group_concat(distinct product order by product) as products from Activities group by sell_date
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288773.html