sql学习笔记
select * from [表名] where species in('value值','value值'); --查找在列表中的行
select distinct * from [表名] where [条件]; --查询不重复的
select * from [表名] order by [字段]; --按某种属性对行进行升序排序
select * from [表名] order by [字段] desc; --按某种属性对行进行降序排序
select * from [表名] order by [字段] desc limit 1; --获得最大的值的第一行
select count(*) from [表名]; --检查其中的行数
select count(*) from [表名] where [条件]; --查询出数据的行数
select sum(字段) from [表名]; --查找给定值的总和
select avg(字段) from [表名]; --查找给定值的平均值
select max(字段) from [表名]; --查找表的最大值
select count(*),[字段] from [表名] group by [字段]; --返回字段的行数
select max(字段),[字段] from [表名] group by [字段]; --返回最大的数据
select * from [表名] where [字段] = (select min(字段) from [表名]); --SQL查询放在另一个SQL查询中
select [表名].[字段],[表名].[字段] from [表名] inner join [表名] on [表名].[字段]=[表名].[字段]; --内连接
select [表名].[字段],[表名].[字段] from [表名] inner join [表名] on [表名].[字段]=[表名].[字段] inner join [表名] on [表名].[字段]=[表名].[字段]; --多连接
select [表名].[字段],[表名].[字段] from [表名] left join [表名] on [表名].[字段]=[表名].[字段] left join [表名] on [表名].[字段]=[表名].[字段]; --左连接
select c.[字段],t.[字段] from [表名] as c left join [表名] as ct on c.[字段]=ct.[字段] left join [表名] as t on ct.[字段]=t.[字段]; --表别名