首页 技术 正文
技术 2022年11月7日
0 收藏 768 点赞 649 浏览 3116 个字

mysql数据库优化课程—9、php用什么写的

一、总结

一句话总结:php是用c语言写的,所以php里面的那些模块什么都是c语言

c

1、php用什么写的?

c

php是用c语言写的,所以php里面的那些模块什么都是c语言

2、google搜索和百度搜索的区别是什么?

质量
资金

google搜索偏向自由,好东西通过关键词就能搜出来

百度的话主要偏向资金,你给的钱多,你的搜索排名就高

3、mysql中如何查询为null的行和不为null的行?

is null

1.查询值为null的行
select * from user where password is null;

is not null

2.查询值不为null的行
select * from user where password is not null;

因为null不能做比较,所以=null是错的

4、mysql中如何使用limit限定输出条数?

limit m,n

使用limit限定输出条数:
1)前5条
select * from user limit 5;
select * from user limit 0,5;

2)从第四条取3条:
select * from user limit 3,3;

5、delete与truncate的区别是什么?

truncate清除计数器

truncate是直接删除表,delete是一行一行的删除,多以truncate速度快的多,所以truncate也会清除计数器

1.delete清空表数据,但不会清除计数器(自增)
delete from user;

2.truncate清空表数据,同时会清除计数器(自增)
truncate user;

6、统计查找的数据的总函数?

count(*)

注意这里这个括号的用法

#统计表总行数:
select count(*) from user;
select count(id) from user;

#统计符合条件的行数:
select count(*) from user where id>2;

7、mysql如何让查出来的字段连接其它字符串,比如在id前面加上id:?

mysql数据库优化课程—9、php用什么写的

concat(‘id:’,id) id

最后一个id表示列的别名

连接函数concat:
1)
select concat(‘id:’,id) id,concat(‘user:’,username) user,concat(‘pass:’,password) pass from user;

2)
select id,username,password,concat(id,’-‘,username,’-‘,password) iduserpass from user;

3)
select (id-1) as id,username,password from user;

8、linux命令行中怎样是复制?

选中

直接选中就是复制了,然后点右键就是粘贴

9、如何从数据库取出来的数据修改索引之后才给调用的位置?

(id-1) as id

select (id-1) as id,username,password from user;

mysql里面支持查询语句列的加减乘除等这些操作

二、内容在总结中

1.查询值为null的行
select * from user where password is null;

2.查询值不为null的行
select * from user where password is not null;

3.使用order by对查询结果排序
#排序分为升序(asc)(从小到大)和降序(desc)(从大到小)
1)升序
select * from user order by id;
select * from user order by id asc;

2)降序
select * from user order by id desc;

使用limit限定输出条数:
1)前5条
select * from user limit 5;
select * from user limit 0,5;

2)从第四条取3条:
select * from user limit 3,3;

delete与truncate的区别:
1.delete清空表数据,但不会清除计数器(自增)
delete from user;

2.truncate清空表数据,同时会清除计数器(自增)
truncate user;

连接函数concat:
1)
select concat(‘id:’,id) id,concat(‘user:’,username) user,concat(‘pass:’,password) pass from user;

2)
select id,username,password,concat(id,’-‘,username,’-‘,password) iduserpass from user;

3)
select (id-1) as id,username,password from user;

随机数rand函数:
select * from user order by rand() limit 1;

统计个数count函数:
#统计表总行数:
select count(*) from user;
select count(id) from user;

#统计符合条件的行数:
select count(*) from user where id>2;

求和sum():
select sum(id) from user;

平均值avg():
select avg(id) from user;

最大值max():
select max(id) from  user;

最小值min():
select min(id) from  user;

user表数据:
+—-+———-+———-+——-+
| id | username | password | class |
+—-+———-+———-+——-+
|  1 | user1    | 123      |     1 |
|  2 | user2    | 123      |     1 |
|  3 | user3    | 123      |     1 |
|  4 | user4    | 123      |     2 |
|  5 | user5    | 123      |     1 |
|  6 | user6    | 123      |     3 |
|  7 | user7    | 123      |     2 |
|  8 | user8    | 123      |     1 |
|  9 | user9    | 123      |     3 |
| 10 | user10   | 123      |     1 |
+—-+———-+———-+——-+

group by分组聚合的使用:
#按条件进行分组,然后在分组的基础上进行有条件的聚合.

把每个班的第一个人取出来:
mysql> select * from user group by class;
+—-+———-+———-+——-+
| id | username | password | class |
+—-+———-+———-+——-+
|  1 | user1    | 123      |     1 |
|  4 | user4    | 123      |     2 |
|  6 | user6    | 123      |     3 |
+—-+———-+———-+——-+

统计每个班的总人数:
mysql> select concat(class,’ 班’) 班级,concat(count(*),’ 人’) 人数 from user group by class;
+——–+——–+
| 班级   | 人数   |
+——–+——–+
| 1 班   | 6 人   |
| 2 班   | 2 人   |
| 3 班   | 2 人   |
+——–+——–+

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905