Mysql基础语句

2018-10-26  本文已影响0人  沈神奇

/*增*/ 

INSERT INTO students (name,age) VALUES ("神奇美",18) /*插入数据*/

/*删*/ 

DELETE FROM students WHERE id = 5 AND NAME = "神奇美"  /*删除数据并没有删除id*/

/*改*/ 

UPDATE students SET sex = "女" WHERE id = 5 /*更新数据*/

/*查*/ 

SELECT * FROM students ORDER BY age DESC  /*查询学生表年两由大到小降序排列 反之ASC是升序*/

SELECT * FROM students ORDER BY age ASC

SELECT * FROM students GROUP BY sex /*根据性别分组*/

SELECT name FROM students /*查询n所有name*/

SELECT * FROM students WHERE sex = "男" /*查询表中条件性别为男的数据*/

SELECT COUNT(1) from students /*统计表中有多少条数据*/

SELECT COUNT(1) from students WHERE sex = "女" /*统计表中性别为女的条数数据*/

/*创建表*/

CREATE TABLE techer (

id INT(11) NOT NULL PRIMARY KEY auto_increment, #id 整形 不能为空 主键 自动递增

name VARCHAR(255)

)

上一篇下一篇

猜你喜欢

热点阅读