码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库基础知识

时间:2018-11-20 13:18:12      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:desc   jquery   类型   har   字符   product   core   多个   l数据库   

/*新建表*/
CREATE TABLE order01(
    oid INT,
    productname VARCHAR(10),
    otime DATETIME,
    money DOUBLE
)
/*添加字段*/
ALTER TABLE order01 ADD COLUMN odesc VARCHAR(50);
/*删除字段*/
ALTER TABLE order01 DROP COLUMN money;
/*修改字段类型*/
ALTER TABLE order01 MODIFY COLUMN otime VARCHAR(20);
/*修改字段名称*/
ALTER TABLE order01 CHANGE COLUMN otime ordertime VARCHAR(20);
/*修改表名*/
ALTER TABLE order01 RENAME TO order02;
/*新增数据*/
INSERT INTO order02 VALUES(1,‘口红‘,‘2018-11-13‘,‘骗女人钱的‘);
INSERT INTO order02(oid,productname,odesc) VALUES(2,‘手表‘,‘骗男人钱的‘);
/*修改数据*/
UPDATE order02 SET ordertime=‘2018-12-12‘ WHERE oid=2;
/*修改多个字段*/
UPDATE order02 SET productname=‘面膜‘,ordertime=‘2018-11-11‘ WHERE oid=1;
/*删除数据*/
DELETE FROM order02 WHERE oid=2;
/*全表删除*/
DELETE FROM order02;
TRUNCATE TABLE order02;
/*查询所有字段*/
SELECT*FROM order02;
/*查询指定字段*/
SELECT oid,productname,odesc FROM order02;
/*查询时添加常量列*/
SELECT oid AS‘编号‘,productname FROM order02;
/*新建成绩表*/
CREATE TABLE score(
    sid INT,
    sname VARCHAR(10),
    ssex CHAR(2),
    html DOUBLE,
    js DOUBLE,
    jquery DOUBLE
);
DROP TABLE score;
SELECT*FROM score;
INSERT INTO score VALUES(1,‘李全‘,‘男‘,88,55,99);
INSERT INTO score VALUES(2,‘张超‘,‘女‘,55,77,94);
INSERT INTO score VALUES(3,‘赵涛‘,‘男‘,11,99,22);
INSERT INTO score VALUES(4,‘冯旭‘,‘女‘,7,8,9);
/*查询时合并列*/
SELECT sname,(html+js+jquery) AS ‘总成绩‘ FROM score;
/*查询时去除重复列*/
SELECT DISTINCT ssex FROM score;
SELECT DISTINCT(ssex) FROM score;
/*逻辑条件查询*/
SELECT * FROM score WHERE sid=1 AND ssex=‘男‘;
SELECT * FROM score WHERE sid=2 OR ssex=‘女‘;
/*比较条件查询*/
SELECT * FROM score WHERE html>=60 AND js<=80;
SELECT * FROM score WHERE html>=60 AND html<=100;
SELECT * FROM score WHERE html BETWEEN 60 AND 100;
SELECT * FROM score WHERE <>60 AND js>8;
INSERT INTO score(sid,sname,ssex,html)VALUES(5,‘高炜城‘,‘男‘,80);
INSERT INTO score(sid,sname,ssex,html)VALUES(6,‘张三‘,‘‘,80);
/*判断是否为null*/
SELECT * FROM score WHERE js IS NOT NULL;
/*判断是否为空字符串*/
SELECT * FROM score WHERE ssex <> ‘‘;
SELECT * FROM score WHERE ssex = ‘‘;
/*模糊查询*/
SELECT * FROM score WHERE sname LIKE ‘张%‘;
SELECT * FROM score WHERE sname LIKE ‘__‘;
SELECT * FROM score WHERE sname LIKE ‘%张%‘;
SELECT SUM(js) AS ‘js成绩‘ FROM score;
SELECT AVG(html) AS ‘html平均成绩‘ FROM score;
SELECT MAX(jquery) FROM score;
SELECT MIN(js) FROM score;
/*求本班多少人*/
SELECT COUNT(*) FROM score;
/*分页查询*/   /*起始行=(当前页-1)*每页显示的条数*/
/*第一页*/
SELECT * FROM score LIMIT 0,1;
/*第二页*/
SELECT * FROM score LIMIT 2,1;
/*查询排序*/
SELECT * FROM score ORDER BY html ASC;
SELECT * FROM score WHERE ssex=‘男‘ ORDER BY html DESC;
SELECT * FROM score ORDER BY js ASC,jquery DESC;
/*分组查询*/
SELECT ssex,COUNT(*) FROM score GROUP BY ssex;
/*查询总人数大于2的性别(HAVING)*/ /*按性别分组*/
SELECT ssex FROM score GROUP BY ssex
HAVING COUNT(*)>2;

mysql数据库基础知识

标签:desc   jquery   类型   har   字符   product   core   多个   l数据库   

原文地址:https://www.cnblogs.com/zhaotao11/p/9988057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!