天天看点

学习了一点sql语句

1.SQL大小写不敏感,

2.select name,name from 表//从数据库中查整张表,

3.select * from 表

4.只输出名字和国家 select name,country from 表

5.在表中,一个列可能会包含多个重复值,有时您也许希望仅仅列出不同(distinct)的值。select distinct name,name from 表 ,输出名字不同的表

select distinct name from 表//从数据库中只查名字

6.Where 子句用于提取那些满足指定标准的记录。select * from 表 where name='安';

7.如果第一个条件和第二个条件都成立,则 AND 运算符显示一条记录。

如果第一个条件和第二个条件中只要有一个成立,则 OR 运算符显示一条记录。AND & OR 运算符用于基于一个以上的条件对记录进行过滤。and 和 or  select * from 表 where country='USA' and id>5;都满足的 。select * from 表 where country='USA' or id>5满足其一

二者结合 select * from 表 where id>5 and (country='USA' or country='中国');

8.ORDER BY 关键字用于对结果集按照一个列或者多个列进行排序。

ORDER BY 关键字默认按照升序对记录进行排序。如果需要按照降序对记录进行排序,您可以使用 DESC 关键字。

select * from 表 order by country,id; select * from 表 order by country (desc); 

9.UPDATE 语句用于更新表中已存在的记录。update 表 set country='USA',alexa=500 where name='菜鸟教程';

10.DELETE 语句用于删除表中的行。delete from 表 where country='USA' and alexa=500;

11.SELECT TOP 子句用于规定要返回的记录的数目。select * from 表 limit 5;

12.LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式。select * from 表 where name like 'G%';  select * from 表 where name like '%oo%';带

13.在 SQL 中,通配符与 SQL LIKE 操作符一起使用。

SQL 通配符用于搜索表中的数据。

在 SQL 中,可使用以下通配符:select * from 表 where name regexp '[^GFs]'下面的 SQL 语句选取 name 以 "G"、"F" 或 "s" 开始的所有网站;select * from 表 where name regexp '^[A-H]'('^[^A-H]')下面的 SQL 语句选取 name 以 A 到 H 字母开头的网站:(下面的 SQL 语句选取 name 不以 A 到 H 字母开头的网站:)

14.IN 操作符允许您在 WHERE 子句中规定多个值。select * from 表 where name in ('中国','USA');

15.BETWEEN 操作符选取介于两个值之间的数据范围内的值。这些值可以是数值、文本或者日期。select * from 表 where alexa (not)between 1 and 20;在或不在

下面的 SQL 语句选取alexa介于 1 和 20 之间但 country 不为 USA 和 IND 的所有网站:select * from 表 where( alexa between 1 and 20 )and not country in('中国','USA');

下面的 SQL 语句选取 name 以介于(不介于) 'A' 和 'H' 之间字母开始的所有网站:select * from 表 where name (not) between 'A' and 'H';