一、基本的查询语句,
1、查询,select * from prsons where lastname in ('admin','cater')
2、新增 ,insert into persons values('yanghua','13456','hunan')
3、删除,delete from person where lastname='wilson'
4、修改,update person set firsname='yanghua' where lastname='yang'
5、平均,select avg(orderprice) as orderaverage from order
6、指定条件行数,select count(customer) as customernilsen from orders where customers='yanghua'
7、返回数据列总和,select sum(column_name) from table_name
8、子查询,select * from student where birthday>(select birthday from student where stuname='zhanghui')
9、多表查询,select persons.lasenem orders.no form persons left join orders
on persons.id=orders.id_p order by persons.lastname
10,现在,我们希望查找订单总金额少于 2000 的客户
SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer
HAVING SUM(OrderPrice)<2000
11、还有其它:
distinict 去重, between 在摸个范围内,
and 如果第一个条件和第二个条件都成立,显示一个查询记录,
or 如果第一个条件和第二个条件要成立一个,显示一个记录,
order by desc 排序,降序,top 2 * 查询头俩条记录,
left 左边,right 右边,like 指定模式查询,
in, 字句中规定多个值,select * into b from a,查询a表数据插入b表中,
as 别名,create database my 创建数据库,create table a 创建表,
first 第一个数据,last 最后一条数据,
max mix 最大值,最小值,group by 分组,,,
12、使用存储,来一下子插入100条数据,
create procedure p8()
begin;
declare a int;
set a=1;
while (a<100) do
insert into building values (a,'a','b');
end while;
end
call p8()
网友评论