微信扫一扫打赏支持

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

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

一、总结

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

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

 

 

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

google:质量
百度:资金

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

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

 

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

is null
is not null

1.查询值为null的行
select * from user where password is 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也会清除计数器

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

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

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

 

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

count(*):select count(*) from user;

注意这里这个括号的用法

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

 

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

 

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

连接函数concat: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 人   |
+--------+--------+

 

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

 

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;

 

 

 
posted @ 2019-05-27 23:30  范仁义  阅读(319)  评论(0编辑  收藏  举报