数据库查询

普通查询分:

普通查询(select 列,列 from 表名)

条件查询(where 列), 单条件_并列条件_或条件

模糊查询(where 列 like'内容%'),

统计查询(count(主键)/max(列)/min(列)/avg(列)/sum(列)),  各组之间用逗号隔开

排序查询(order by 列 desc),

分组查询(group by 列),

分页查询(limit (n-1)*x , x)

高级查询分:查询多个表

连接查询 (对列的扩展 / 相同的列要加表名,不同的列不用加表名)

      形式1: select*from 表1,表2  where  表1.列0 = 表2.列0 

      形式2: select*from 表1  join 表2  on  表1.列0 = 表2.列0

联合查询(对行的扩展)

     select*from info where nation = 'n001'   union   select*from info where code = 'p003'

无关子查询( 外查询不引导内查询 )

      select*from Info where nation = ( select code from Nation where name='汉族')

      select*from Info where nation in ( select code from Nation where name='汉族' or name='回族')    //多条件时用 in 不用=

相关子查询 ( 外查询引导内查询 )

      select*from car b where b.oil<(select avg(a.oil) from car a where a.brand = b.brand)    //查询同一系列的油耗比平均油耗低的汽车信息,

原文地址:https://www.cnblogs.com/hellodp/p/5272194.html