zoukankan      html  css  js  c++  java
  • 9、select 语句

    基础语句
    select * from tb1;
    select * from tb1 limit 3;
    select name,age from tb1;
    
    select name,age from tb1 where age = 25;
    select * from tb1 where age != 28;
    select * from tb1 where age >= 25 and age <=28;
    select name,age from tb1 where age between 25 and 28;
    select * from tb1 where age = 25 or age = 28;
    select * from tb1 where age not between 25 and 28;
    select * from tb1 where age < 25 or age > 28;
    
    select * from tb1 where name like 'j%';
    select * from tb1 where name like 't__';
    select * from tb1 where name rlike '^t.*';
    
    select * from tb1 where age in (22,23,24,25);
    select * from tb1 where age not in (28,33,43);
    
    select * from tb1 order by age;
    select * from tb1 order by age asc;
    select * from tb1 order by age desc;
    select * from tb1 order by age desc,name asc;
    
    select distinct age from students; #去重查询
    select name as StuName,age from tb1;
    
    分组与聚合
    select gender,sum(age) from students group by gender;
    select classid,avg(age) as avgage from students group by classid having avgage > 25;
    select sum(age) from students where age > 19 group by gender;
    
    多表查询
    # 交叉连接
    select * from t1 cross join t2 cross join t3;
    select * from t1,t2,t3;
    # 内连接
    select * from t1 inner join t2 on t1.t1id=t2.t2id;
    select * from t1,t2 where t1.t1id=t2.t2id;
    # 外连接
    select * from t1 right outer join  t2 on t1id=t2id;
    select * from t1 left outer join  t2 on t1id=t2id;
    select * from t1 right  join  t2 on t1id=t2id;
    select * from t1 left join  t2 on t1id=t2id;
    #联合查询
    select * from t1 union select * from t2;     #重复数据合并
    select * from t2 union all select * from t4; #显示重复记录
    #全连接
    > 
    
  • 相关阅读:
    flash不保存在IE缓存中
    pv 3d
    ASP.NET优化
    根据文件名判断文件扩展名 和 根据流真正判断文件类型的关键函数
    as3.0
    编码
    AS3中Event的target和currentTarget
    显示用户IP来源的代码
    启用IIS的Gzip压缩功能
    Css之多个子元素水平平均分布——flex布局法
  • 原文地址:https://www.cnblogs.com/kcxg/p/10382465.html
Copyright © 2011-2022 走看看