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; #显示重复记录
    #全连接
    > 
    
  • 相关阅读:
    泛型中的类型擦除
    chatty: uid=10549(u0_a549) com.exampleidentical 40 lines
    Android 属性动画ObjectAnimator和ValueAnimator讲解
    解决Error:Unable to find method 'org.gradle.api.internal.project.ProjectInternal.
    Android Studio 模拟器无法打开 emulator: ERROR: x86 emulation currently requires hardware
    有关 java 不定参数
    数据处理
    有关SharedPreference的使用
    关于Fragment的onActivityResult 不执行
    Java GC回收机制
  • 原文地址:https://www.cnblogs.com/kcxg/p/10382465.html
Copyright © 2011-2022 走看看