查询语句:
SELECT * FROM qqsystem SELECT * FROM cardidsystem SELECT * FROM dormoitorysystem SELECT * FROM empsystem SELECT * FROM fictionsystem SELECT * FROM kingusersystem SELECT * FROM wechatsystem SELECT * FROM booksystem
#查询字段的语句 查一个字段 查俩个字段 查三个字段 插死个字段 查五个字段...... 查多个字段 SELECT * FROM smbms.emp SELECT * FROM smbms_role SELECT * FROM smbms_user SELECT * FROM smbms_bill SELECT * FROM smbms.student #*代表查询所有的字段 我的建议步能这样写.以emp为例 #@1查询表第字段练习 # 1 查询 id SELECT id FROM emp # 2 查询 id workno SELECT id, workno FROM emp # 3 查询 id wokno name SELECT id, workno, NAME FROM smbms.emp # 4 查询 id wokno name sex SELECT id, workno, NAME, sex FROM smbms.emp # 5 查询id wokno name sex age SELECT id, workno, NAME, sex, age FROM smbms.emp # 6 查询id wokno name sex age idcard SELECT id, workno, NAME, sex, age, idcard FROM smbms.emp # 7 查询 id wokno name sex age idcard workaddress SELECT id, workno, NAME, sex, age, idcard, workaddress FROM smbms.emp # 8 查询 id wokno name sex age idcard workaddress address SELECT id, workno, NAME, sex, age, idcard, workaddress, address FROM smbms.emp # 9 查询 id wokno name sex age idcard workaddress address entrydate SELECT id, workno, NAME, sex, age, idcard, workaddress, address, entrydate FROM smbms.emp # 10 查询 id wokno name sex age idcard workaddress address entrydate home SELECT id, workno, NAME, sex, age, idcard, workaddress, address, entrydate, home FROM smbms.emp #11 查询指定的字段名 1 wokno sex age home SELECT workno, sex, age, home FROM smbms.emp SELECT * FROM smbms.emp #@2查询 所有的 id 起个名字 SELECT id AS '学生编号' FROM smbms.emp SELECT id '教师编号' FROM smbms.emp SELECT id '职工标号', workno '职工工作id', NAME '职工姓名' FROM smbms.emp #@3 查询地址不能重复 SELECT * FROM smbms.emp SELECT DISTINCT workaddress '工作地址' FROM smbms.emp #如果上面的明白了请操作下面的表 SELECT * FROM smbms_role SELECT * FROM smbms_user SELECT * FROM smbms_bill SELECT * FROM smbms.student #更据上面的内容举一反三 #条件查询 多了一个 WHERE 为了将时间缩小 大于 小于 等于 不等于 范围 SELECT * FROM smbms.emp WHERE age = 23;#最小值 SELECT * FROM smbms.emp WHERE age = 29;# 最大值 SELECT * FROM smbms.emp WHERE age = 26; SELECT * FROM smbms.emp WHERE age > 26; SELECT * FROM smbms.emp WHERE age < 25; SELECT * FROM smbms.emp WHERE age >= 25; SELECT * FROM smbms.emp WHERE age <= 25; SELECT * FROM smbms.emp WHERE age = 22 AND sex = '女'; SELECT * FROM smbms.emp WHERE age > 22 AND sex = '男';#查询字段为俩个字段级的数据 信息 -- % SELECT * FROM smbms.emp WHERE NAME LIKE '__';#查询字段为三个字段级的数据 信息 -- % SELECT * FROM smbms.emp WHERE NAME LIKE '___';#查询指定的sql字段 SELECT * FROM smbms.emp WHERE NAME LIKE '%三'; SELECT * FROM smbms.emp WHERE NAME LIKE '%二'; SELECT * FROM smbms.emp WHERE NAME LIKE '%自由'; SELECT * FROM smbms.emp WHERE NAME LIKE '%自由' AND sex = '女'; SELECT * FROM smbms.emp WHERE idcard LIKE '%986'; SELECT * FROM smbms.emp WHERE idcard LIKE '%86'; SELECT * FROM smbms.emp WHERE idcard LIKE '%00';#查询没有身份证的信息 SELECT * FROM smbms.emp WHERE idcard IS NULL #查询有身份证的信息 SELECT * FROM smbms.emp WHERE idcard IS NOT NULL #查询没有家庭地址的信息 SELECT * FROM smbms.emp WHERE home IS NULL #查询有家庭地址的信息 SELECT * FROM smbms.emp WHERE home IS NOT NULL #查序位于两者之间的数据 SELECT * FROM smbms.emp WHERE age >= 23 && age <= 29; SELECT * FROM smbms.emp WHERE age >= 23 AND age <= 29; SELECT * FROM smbms_bill SELECT * FROM smbms_bill WHERE totalPrice = 2000; SELECT * FROM smbms_bill WHERE totalPrice = 25000; SELECT * FROM smbms_bill WHERE totalPrice > 2500; SELECT * FROM smbms_bill WHERE totalPrice > 2000 AND totalPrice < 25000;#聚合查询 count max min avg sum 几个常用的函数 #第一个函数的使用count SELECT * FROM smbms.emp SELECT count(*) '数量' FROM smbms.emp SELECT * FROM smbms_role SELECT count(*) '记录' FROM smbms.smbms_role SELECT FROM smbms_role SELECT count(*) '表中记录' FROM smbms.smbms_bill SELECT * FROM smbms_bill SELECT count(*) '表中记录' FROM smbms.student #第二个函数的使用 max min SELECT max( age ) FROM smbms.student SELECT min( age ) FROM smbms.emp SELECT max( id ) FROM smbms_role SELECT max( id ) FROM smbms_user SELECT max( totalPrice ) FROM smbms_bill SELECT min( totalPrice ) FROM smbms_bill SELECT min( age ) FROM smbms.student #第三个函数的使用 avg SELECT avg( age ) FROM smbms.student SELECT avg( totalPrice ) FROM smbms_bill #第三个函数的使用 sum SELECT sum( age ) '求和' FROM smbms.student SELECT sum( totalPrice ) FROM smbms_bill #分组查询 SELECT * FROM smbms.emp SELECT sex, count(*) FROM smbms.emp GROUP BY sex SELECT sex, avg( age ) FROM smbms.emp GROUP BY sex #排序查询 #升序 SELECT * FROM smbms.emp ORDER BY age ASC; #降序 SELECT * FROM smbms.emp ORDER BY age DESC; SELECT * FROM smbms.emp SELECT * FROM smbms.emp ORDER BY age ASC; SELECT * FROM smbms.emp ORDER BY age DESC; SELECT * FROM smbms.student SELECT * FROM smbms.student ORDER BY age ASC; SELECT * FROM smbms.student ORDER BY age DESC;#id SELECT * FROM smbms.smbms_bill ORDER BYRDER BY id ASC; SELECT * FROM smbms.smbms_bill ORDER BY id DESC;#billCode SELECT * FROM smbms.smbms_bill ORDER BYRDER BY billCode ASC; SELECT * FROM smbms.smbms_bill ORDER BY billCode DESC;#creationDate SELECT * FROM smbms.smbms_bill ORDER BYRDER BY creationDate ASC; SELECT * FROM smbms.smbms_bill ORDER BY creationDate DESC;
#查询两个字段 SELECT smbms_bill.id,smbms_bill.billCode FROM smbms_bill #查询三个字段 SELECT smbms_bill.id,smbms_bill.billCode,smbms_bill.productCount FROM smbms_bill #查询五个字段 SELECT smbms_bill.id,smbms_bill.billCode,smbms_bill.productCount,smbms_bill.productDesc,smbms_bill.productUnit FROM smbms_bill #查询六个字段 SELECT smbms_bill.id,smbms_bill.billCode,smbms_bill.productCount,smbms_bill.productDesc,smbms_bill.productUnit,smbms_bill.productUnit,smbms_bill.totalPrice FROM smbms_bill #查询所有数据 SELECT * FROM smbms_bill
增加语句
INSERT INTO `emp` VALUES (0, '张三', '男', 34, '2022-05-10', '行政管理部门'); INSERT INTO `emp` VALUES (0, '李四', '女', 23, '2022-05-10', '前端开发部门');
#增加 INSERT INTO `demossmtest`.`wechatid`(`wechatid`, `name`, `password`, `area`, `phone`, `sex`, `age`) VALUES (1005, '自由的少年', 123656, '湖口', 1235678342, '女', 23),(1006, '你人人网', 143656, '南昌', 1235778342, '女', 33),(1007, '你认为的年少', 223656, '上海', 1235978342, '女', 23) INSERT INTO `demossmtest`.`empsystem`(`empid`, `name`, `sex`, `carid`, `pay`, `branch`, `occupation`) VALUES (1004563, '吴胜赢', '男', '六号', 27456, '计算机', '软件') INSERT INTO `demossmtest`.`fictionsystem`(`noveid`, `name`, `sex`, `age`, `novetype`, `integral`, `chapternumber`) VALUES (2001002, '思考', '女', 23, '科幻', '325', 120),(2001003, '思想', '男', 33, '武打', '385', 130),(2001004, '人生的自愈', '男', 33, '言情', '345', 120) INSERT INTO `demossmtest`.`dormoitorysystem`(`dorid`, `name`, `age`, `occupation`, `buildinglayer`, `storey`) VALUES (3001002, '管理员', 34, '宿管阿姨', '三栋', '三楼'),(3001003, '年少无知', 36, '管理员', '1栋', '三楼'),(3021004, '塑形衣', 34, '宿管员', '2栋', '三楼') INSERT INTO `demossmtest`.`booksystem`(`bookid`, `scribe`, `price`, `number`, `redingwriter`, `dianjinumber`) VALUES (3001001, '《人生》', 23, 34, '王晓丽', 345), (3001201, '《人生的意义》', 23, 34, '王晓丽', 345), (3001003, '《我想要的人生》', 23, 34, '王晓丽', 345), (3001001, '《人生的第一页》', 23, 34, '自由的人生', 345), (3001001, '《想到的人生》', 23, 34, '王小明', 345) INSERT INTO `demossmtest`.`kingusersystem`(`kinguseid`, `name`, `sex`, `age`, `numberking`, `san`, `commomheror`) VALUES (900891002, '阮小明', '女', 23, 1300, '白银', '后裔'),(900892003, '如昂子开', '女', 23, 1300, '青铜', '鲁班'),(900891005, '紫晓峰', '女', 23, 1300, '王者', '米拉提'),(900891002, '消字号', '女', 23, 1300, '最强王者', '师傅') INSERT INTO `demossmtest`.`cardidsystem`(`id`, `name`, `age`, `dateime`, `carid`, `address`, `native`) VALUES (NULL, '胡紫菜', 23, '2022-08-02 12:03:52', 3899872, '江西九江', '九江') INSERT INTO `demossmtest`.`csdnsystem`(`name`, `age`, `sex`, `csdnid`, `csdnphone`, `csdnaddress`, `csdnrecord`, `csdnnumber`, `csdnredingnumber`, `csdncolumn`, `csdncontent`, `resource`) VALUES ('行政', 23, '男', 1009002, '1896787674', '九江', '8', 223, 7997, 'mysql', '9', '2'),('小王', 33, '女', 1209002, '1856787674', '南昌', '8', 233, 7987, 'java', '19', '2'),('小清河', 22, '女', 1009032, '6896787674', '上海', '8', 923, 8997, 'JavaScript', '9', '2'),('行政', 23, '男', 1009802, '1896787474', '九江', '8', 220, 7997, 'jquery', '9', '2')
修改语句
#修改语句 修改一个字段 #语法格式 UPDATE 数据库.表名 set '修改的字段名'='修改的内容' WHERE '学号'='学号编号内容' UPDATE `smbms`.`student` SET `name` = '我是第一条数据' WHERE `id` = 1005032901 UPDATE `smbms`.`student` SET `name` = '我是第二条数据' WHERE `id` = 1005032902 #修改二个字段 UPDATE `smbms`.`student` SET `name` = '我是第三条语句', `age` = 3 WHERE `id` = 1005032903 UPDATE `smbms`.`student` SET `name` = '我是第四条语句', `age` = 4 WHERE `id` = 1005032904 #总结如果遇到修改语句 #UPDATE 数据库的名称.数据库的 # `name` = '我是第四条语句', `age` = 4 ===》变量A='',B='',C=''.......... #表名 set 表的字段名=修改的内容 主键="索引的第几天记录" #修改 三个字段呢? UPDATE `smbms`.`student` SET `id` = 1005032910, `name` = '我是修改的主键内容', `age` = 5 WHERE `id` = 1005032905 UPDATE `smbms`.`student` SET `id` = 1005032911, `name` = '我是修改的主键内容2', `age` = 5 WHERE `id` = 1005032906 SELECT * FROM smbms.student #建议下面语句的写法 SELECT id, NAME, age FROM smbms.student #删除表中的一条记录 我要王小八 王小七删除 DELETE FROM `smbms`.`student` WHERE `id` = 1005032909 DELETE FROM `smbms`.`student` WHERE `id` = 1005032908 #上面是基础的操作接下来来点难度 这是以后工作最基础的表难度 #操作的表为
/* Navicat Premium Data Transfer Source Server : demossmtest Source Server Type : MySQL Source Server Version : 80023 Source Host : localhost:3306 Source Schema : demossmtest Target Server Type : MySQL Target Server Version : 80023 File Encoding : 65001 Date: 02/06/2022 22:26:59 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for booksystem -- ---------------------------- DROP TABLE IF EXISTS `booksystem`; CREATE TABLE `booksystem` ( `id` int NOT NULL AUTO_INCREMENT, `bookid` int NULL DEFAULT NULL, `scribe` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, `price` int NULL DEFAULT NULL, `number` int NULL DEFAULT NULL, `redingwriter` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, `dianjinumber` int NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of booksystem -- ---------------------------- INSERT INTO `booksystem` VALUES (1, 3001001, '张三', 23, 34, '李四', 345); INSERT INTO `booksystem` VALUES (2, 3001001, '《人生》', 23, 34, '王晓丽', 345); INSERT INTO `booksystem` VALUES (3, 3001201, '《人生的意义》', 23, 34, '王晓丽', 345); INSERT INTO `booksystem` VALUES (4, 3001003, '《我想要的人生》', 23, 34, '王晓丽', 345); INSERT INTO `booksystem` VALUES (5, 3001001, '《人生的第一页》', 23, 34, '自由的人生', 345); INSERT INTO `booksystem` VALUES (6, 3001001, '《想到的人生》', 23, 34, '王小明', 345); SET FOREIGN_KEY_CHECKS = 1;