1.HAVING 子句以及统计字句;
在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用。
select customer,Sum(orerprice)as 总数 from orders group by customer having sum(orderprice)<2000
select top 5 Avg(ScoreOverall)as 前五个平均数 from Review
select top 5 * from Review where ScoreOverall > (select AVG(ScoreOverall)as大于平均数 from Review)
select min(ScoreOverall) as 最小数 from Review
select COUNT(distinct ScoreOverall ) as 去重个数 from Review
select Sum(ScoreOverall) as 总数 from Review
select COUNT(ScoreOverall) as 四十的个数 from Review where ScoreOverall = '40'
2.INSERT INTO 语句
INSERT INTO 语句用于向表格中插入新的行。语法:INSERT INTO 表名称 VALUES (值1, 值2,....)
在指定的列中插入数据:insert into Persons (LastName, Address) VALUES ('Wilson', 'Champs-Elysees')
3.Update 语句
Update 语句用于修改表中的数据。语法:UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
UPDATE Person SET Address = 'Zhongshan 23', City = 'Nanjing' WHERE LastName = 'Wilson'
4.DELETE 语句
DELETE 语句用于删除表中的行。语法:DELETE FROM 表名称 WHERE 列名称 = 值
DELETE FROM Person WHERE LastName = 'Wilson'
1>.删除所有行
可以在不删除表的情况下删除所有的行。这意味着表的结构、属性和索引都是完整的:
DELETE FROM table_name
5.LIKE 操作符(也即是模糊查询);也包含not like
LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式。:"%" 可用于定义通配符(模式中缺少的字母)。例
如:'%N','N%','%N%';
select * from review where city like '%n'
6.IN 操作符
IN 操作符允许我们在 WHERE 子句中规定多个值。可以添加某个字段的多个值进行限制;
select * from review where city in('beijing','shanghai')
7.BETWEEN 操作符
操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。(包含value1不
包含value2);
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2