您的位置:首页 > 数据库

sql常用查询语句

2014-01-25 16:08 357 查看
--1、一般查询语句

select colunm from table;

--2、过滤重复

select distinct column from table;

--3、增加选择条件

select column from table where condition

where and

where or

where between and

where in()

--4、模糊查询

select column from table like keywords like %_;

--5、多表查询

select table1.colunm, table2.colunm from table1,table2

where condition

--二、组函数(avg()、sum())\分组函数(group by)\排序(order by)bbb

--1、组函数 avg\sum\max\min\count

--2、分组函数

group by column

having condition

select avg(salary),department_id from employees

group by department_id

having avg(salary)>1000;

--3、排序

order by

select last_name,salary from employees order by salary

select last_name,hire_date from employees order by hire_date desc;

--4、子查询

select * from employees where salary =

(select salary from employees where last_name ='joll');

select * from employees where salary =(select max(salary) from employees);

select * from employees where salary in ();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: