1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| # DQL条件查询语句
# 按条件表达式进行筛选
# 筛选工资大于12000的人 SELECT * FROM employees WHERE salary>12000; # 查询部门编号不等于90号的员工姓名和部门编号 SELECT CONCAT(first_name,' ',last_name) 姓名,department_id 部门编号 FROM employees WHERE department_id<>90;
# 按逻辑表达式筛选
# 查询工资再10000-20000之间的员工部分信息 SELECT first_name, last_name, salary, commission_pct FROM employees WHERE salary > 10000 AND salary < 20000; # 查询工资高于15000,或者部门编号不为90的员工 SELECT last_name, salary, department_id FROM employees WHERE salary>15000 OR department_id<>90;
# 模糊查询
SELECT last_name, salary FROM employees WHERE last_name LIKE '_o__h%'; #假设要查询的内容中包含通配符,可以用转义字符解释内容,或用转义关键字 SELECT last_name, job_id, salary FROM employees WHERE job_id LIKE '__\_%'; SELECT last_name, job_id, salary FROM employees WHERE job_id LIKE '__$_%' ESCAPE '$';
#查询员工号在100-120之间 SELECT * FROM employees WHERE employee_id BETWEEN 100 AND 120;
SELECT last_name, job_id FROM employees WHERE job_id IN('IT_PROG','AD_VP','AD_PRES');
SELECT last_name, commission_pct FROM employees WHERE commission_pct IS NULL;
SELECT last_name, commission_pct, job_id FROM employees WHERE job_id <=> 'SA_REP' OR commission_pct <=> NULL;
|