菜到别人想骂我~蠢
1.SQL round函数
(1)语法:round(value,n)
(2)用法:对某个数值(字段)保留指定小数位数(四舍五入)。
例1:
select package,
round(revenue,2) as rev
from product
注:保留收入2位小数
例2:按产品名分组获取求和收益并保留两位小数点,按收益降序排序。
select name,
round(sum(revenue),2) as rev
from product
group by name
2.select count(1),id from 表 group by id having count(1)>1;
查看是否有重复的以id作为查看列.
3.left函数
LEFT(str,length); 截取字符串
SELECT LEFT(‘MySQL LEFT’, 5)
mysql> SELECT LEFT(‘MySQL LEFT’, 5);
±----------------------+
| LEFT(‘MySQL LEFT’, 5) |
±----------------------+
| MySQL |
±----------------------+
4.replace函数 替换
语法:replace(object,search,replace)
语义:把object对象中出现的的search全部替换成replace。
实例:
update hellotable set ‘helloCol’ = replace(‘helloCol’,‘helloSearch’,‘helloReplace’);
5.concat函数
将多个字符串连接成一个字符串。
concat(str1, str2,…) 返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null
select concat(“a”,“b”,“c”);
输出:abc
注:
Mysql 的 concat 函数在连接字符串的时候,只要其中一个为 NULL
则返回值为 NULL.
select concat(“1”,“2”,null);
输出结果:NULL
参考文章:SQL ROUND() 函数 | 菜鸟教程 (runoob.com)
group by函数的具体用法参考:SQL的group by函数的用法实例_小白修炼晋级中的博客-CSDN博客
order by函数的具体用法参考:SQL的order by函数语法及其用法实例——排序方式_小白修炼晋级中的博客-CSDN博客