MySql使用笔记

1、replace函数

去除company_name这一列中包含‘/’这一字符
update stang_bid_envelope set company_name=REPLACE(company_name,’/’,”) WHERE company_name LIKE ‘%/’

2、SUM函数

根据company_name分组统计span字段大于0、等于0、小于0的次数
SELECT company_name,SUM(case when span > 0 then 1 else 0 end) as sum1, SUM(case when span = 0 then 1 else 0 end) as sum2,SUM(case when span < 0 then 1 else 0 end) as sum3 FROM stang_bid_envelope WHERE rank != 0 GROUP BY company_name

3、对字符型的数值进行降序或者升序排序

SELECT * FROM stang_bid_envelope WHERE company_name = ‘中铁十一局集团有限公司’ AND bid_price != ” ORDER BY (bid_price+0) DESC

你可能感兴趣的:(数据库)