DQL基本查询
1.查询多个字段
select 字段1,字段2,字段3... from 表名;
select * from 表名;
2.设置别名
select 字段1 [as 别名],字段2 [as 别名],字段3 [as 别名]... from 表名;
3.去除重复记录
select distinct 字段列表 from 表名;
DQL条件查询:select 字段列表 from 表名 where 条件列表;
代码:
insert into emp (id, workId, name, sex, age, idcard, ertrydate) values (1,'2002','张三三','男',16,'2043','2002-12-03'),(2,'2003','李四','男',26,'2044','2002-11-03'),
(3,'2004','王五','男',17,'2045','2002-10-03'),
(4,'2005','老六六','男',18,'2046x','2002-1-03'),
(5,'2006','老七','男',19,'2047','2002-2-03'),
(6,'2007','老八','男',20,'2048','2002-3-03');
select * from emp;
select id as '编号' from emp;
select distinct sex from emp;
select * from emp where age=18;/*查询年龄等于88的员工*/
select * from emp where age<18;/*查询年龄小于18的员工*/
select * from emp where age!=18;/*查询年龄不等于18的员工*/
select * from emp where idcard is null;/*查询身份证号为空的员工*/
select * from emp where age between 16 and 18;/*查询年龄为16到18的员工*/
select * from emp where age=16 or age=18 or age=20;/*查询年龄为16或18或20的员工*/
select * from emp where age in(16,18,20);/*查询年龄为16或18或20的员工*/
/*like占位符:模糊匹配(_匹配单个字符,%匹配任意个字符) */
select * from emp where name like '___';/*查询名字为两个字的员工信息 */
select * from emp where idcard like '%x';/*查询身份证号最后一位为x的员工信息 */
select * from emp where idcard like '____x';/*查询身份证号最后一位为x的员工信息 */ 标签:18,age,查询,emp,DQL,where,select From: https://www.cnblogs.com/123456dh/p/17284288.html