A-A+

SQL基本语法(二)查询

2016年01月12日 sql 暂无评论 阅读 2,550 views 次

 

查询

SELECT * FROM table;

SELECT column1,column2 FROM table;

SELECT DISTINCT column FROM table;

SELECT * FROM table WHERE id > 8; 其他符号(=、!=、>、<、>=、<=)

 

模糊查询

SELECT * FROM table where name LIKE 'Se_en'; 通配符(%)

SELECT * FROM table WHERE name LIKE '%man%';

 

select * from movies where name between 'A' and 'J';

select * from movies where year between 1990 and 2000;

select * from movies where year between 1990 and 2000 and genre = 'comedy';

 

select * from movies where genre='comedy' or year <1980;

 

排序

select * from movies order by imdb_rating DESC; desc降序,asc升序

select * from movies order by imdb_rating ASC limit 3; limit限制数量

 

 

总结

SELECT is the clause you use every time you want to query information from a database.

WHERE is a popular command that lets you filter the results of the query based on conditions that you specify.

LIKE and BETWEEN are special operators that can be used in a WHERE clause

AND and OR are special operators that you can use with WHERE to filter the query on two or more conditions.

ORDER BY lets you sort the results of the query in either ascending or descending order.

LIMIT lets you specify the maximum number of rows that the query will return. This is especially important in large tables that have thousands or even millions of rows.

标签:

给我留言