-- 创建表 CREATE TABLE zhangwu11 ( id INT PRIMARY KEY AUTO_INCREMENT, -- 账务ID zname VARCHAR(200), -- 账务名称 zmoney DOUBLE -- 金额 ); RENAME TABLE zhangwu11 TO zhangwu -- 修改表名 -- 插入表记录: INSERT INTO zhangwu(id, zname, zmoney) VALUES (1,'吃饭支出',247); INSERT INTO zhangwu(id, zname, zmoney) VALUES (2,'工资收入',12345); INSERT INTO zhangwu(id, zname, zmoney) VALUES (3,'服装支出',1000); INSERT INTO zhangwu(id, zname, zmoney) VALUES (4,'吃饭支出',325); INSERT INTO zhangwu(id, zname, zmoney) VALUES (5,'股票收入',8000); INSERT INTO zhangwu(id, zname, zmoney) VALUES (6,'打麻将支出',8000); INSERT INTO zhangwu(id, zname, zmoney) VALUES (7,NULL,5000); SELECT id,zname FROM zhangwu;-- 查询指定字段信息 UPDATE zhangwu SET zname='吃饭支出' ,zmoney=100 WHERE id=1; -- 更新表记录 INSERT INTO zhangwu VALUES (11,'上学支出',7000); -- 向表中插入所有列 INSERT INTO zhangwu (zname,zmoney) VALUES ('上学支出',7000);-- -- 向表中插入某些列 SELECT * FROM zhangwu -- 查询所有数据 SELECT zname,zmoney FROM zhangwu;-- 查询指定列数据 SELECT zname,zmoney AS money FROM zhangwu;-- 别名查询,使用的as关键字 SELECT zname,zmoney+1000 AS money FROM zhangwu; -- 直接对列进行运算 SELECT * FROM zhangwu WHERE zmoney>100; -- 条件查询 SELECT * FROM zhangwu WHERE zmoney IN(100,1000); -- 条件查询 SELECT * FROM zhangwu WHERE zmoney BETWEEN 100 AND 100000; -- 包含查询 SELECT * FROM zhangwu WHERE zname LIKE '%支出'; -- 模糊查询 SELECT * FROM zhangwu WHERE zname LIKE '吃___'; -- 匹配字符 SELECT * FROM zhangwu ORDER BY zmoney ASC; -- 升序查询 SELECT * FROM zhangwu ORDER BY zmoney DESC; -- 降序查询 SELECT SUM(zmoney) FROM zhangwu; -- 计算数值整合 SELECT COUNT(zmoney) FROM zhangwu; -- 统计不为null的行 SELECT MAX(zmoney) FROM zhangwu; -- 计算最大值 SELECT MIN(zmoney) FROM zhangwu; -- 计算最小值 SELECT AVG(zmoney) FROM zhangwu; -- 计算平均值 SELECT * FROM zhangwu WHERE zmoney IS NOT NULL; -- 查询指定列 非空信息 SELECT * FROM zhangwu WHERE zmoney IS NULL; -- 查询指定列 为空信息 SELECT zname,SUM(zmoney) AS money FROM zhangwu -- 求zmoney总和给money WHERE zname IS NOT NULL -- zname不为空 GROUP BY zname -- 进行分组 HAVING money >1000 -- 条件查询 ORDER BY money DESC -- 进行排序