sql一些问题

1.MySQL数据库有哪些内置函数?

项目中经常用到的,count(1),count(1)比count(*)效率高,sum,计算综合,max,一列中的最大值,min一列中的最小值,to_data("","format")时间格式化,用来比较时间大小
/**1.数学函数 2.字符串函数 3.日期和时间函数 4.条件判断函数
5.系统信息函数 6.加密和压缩函数 7.聚合函数
8.格式或类型转化函数。 说这么多,感觉没啥用 **/

2.如何返回一张表的数据条数?
Select count(1) from tablename;

3.数据库基本操作,
增加:insert into tablename (要添加的列名称) values (要插入的数据);
删除:delete from tablename where ...;
查询:select * from tablename where ...
更新:update tablename set 列名=values where ...

更改表结构
alter table tablename add 列名称 数据类型 位置(一般为after)


4.如何去除重复元素,
select distinct * from tablename

select name from tablename group by name 分组同样也可以

5.根据专业排名
select count(1),专业 from tablename group by  专业 count(1) order by desc count(1)

6.判断 是否为数字?
可以用正则表达式,str.match("[0-9]+")判断
7.截取字符串
用字符串自带的subString(begin,end) 方法。
比如abcd,截取ab就是subString(0,2).

世间种种的诱惑,不惊不扰我清梦
原文地址:https://www.cnblogs.com/javalisong/p/10135121.html