
MySql
文章平均质量分 61
记录于此
u013408863
这个作者很懒,什么都没留下…
展开
-
sql语句sum后的值总是对不上(科学计数法,replace函数)
1.数据库存的是科学计数法,123,2.2replace(字段,",","")select sum(replace("money",",","")) from user ;注意:这里查一查为什么sum(123,2.2),sum之后的数据不准确 replace函数是如何运用的2.@如何运用sql变量set @var_id = (select id from user where name='小白粥粥');select sum(money) from user_...原创 2021-02-01 16:43:25 · 3922 阅读 · 0 评论 -
mysql 查询最近两周,总数量每天的递增情况
1.场景我们常常会遇到这样的一个场景,即老板想要看折线图,每天用户的总增长数,比如2020.11.28200人,2020.11.29 202人,2020.11.30 205人。todo贴图2.sqlselect s.date as "日期", (select count(1) from user t1 where date_format(t1.create_time,'%Y-%m-%d') <= s.date) as "总量"from( select date_.原创 2021-02-01 15:02:13 · 1889 阅读 · 2 评论 -
mysql 查询本月,本周的数据
1.获取本月的数据select count(*) as monthNum from userwhere DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%T%m');date_format(date,format) 用于以不同的格式显示日期/时间数据date:合法的日期format:规定日期/时间的输出格式 基本上都以%开头。其中,常见的有:%Y(年,4位) %y...原创 2021-01-29 14:45:20 · 6257 阅读 · 0 评论 -
mysql中,字段类型为tinyint(1),在查询时为啥不显示正常的数字而是true或false?
背景在查询数据的时候发现gender字段应该显示1,2,3,4这样的数字,但是查出来却是true或false这样的boolean类型。不免产生疑问,为何education字段也是存的数字,就能正确显示出数字,而gender不行,我又查看字段,发现这两个字段的类型不一样。...原创 2020-12-24 17:17:19 · 3335 阅读 · 1 评论 -
mysql中find_in_set()函数
1.场景假设有一个user用户表,表字段分别为:id(主键),name(姓名),age(年龄),hobby(爱好)。而一个人可能有好几个爱好,游泳啊篮球啊乒乓球啊等等。数据库里hobby字段存的是:游泳,篮球,乒乓球而要想查所有喜欢游泳的人,就可以用find_in_set函数了todo:贴图2.使用select *from user where find_in_set("游泳",hobby);3.解释find_in_set(str,strList) 查询strList中包含st.原创 2020-11-16 15:14:46 · 248 阅读 · 0 评论 -
Mysql常见语句
1、增加字段alter table 表名 add 列名 varchar(20) default null comment '注释' after 某列名;例:在user表增加备注字段125长度,在username列后 alter table user add remarks varchar(125) default null comment '备注' after username;2、修改字段① 修改字段属性alter table 表名 modify 字段名称 类型(完整...原创 2020-07-11 22:41:05 · 172 阅读 · 0 评论