zoukankan      html  css  js  c++  java
  • mysql常见的查询语句

    select * from 表名     查询此表所有数据 
    select * from 表名 where 字段名 > 判断条件      查询某表中的某字段符合条件的数据
    select * from 表名 where 字段名 = 判断条件      查询某表中的某字段等于条件的数据
    select * from 表名 where 字段名 like '%灵'        查询某表中的某字段以灵结尾的数据
    select * from 表名 where 字段名 not  like '%灵'        查询某表中的某字段不是以灵结尾的数据
    select * from user where students like '%小%'    查询表 user 中字段 students 包含'小'字的所有内容
    select * from user where score in (98,92)       查询表 user 中字段 score 为98,92的所有内容
    select * from user where score > 95 OR gender='女'  查询表 user 中字段 score 大于95 或者 gender 为女性的所有内容
     
    select * from user,user_ext where user.id = user_ext.id   合并查询表 user 和表 user_ext 中 id 相同的所有数据
    select count(*) from user where score >60   获取表 user 中字段 score 大于 60 的内容数量
    select avg(score) from user   获取表 user 中字段 score 的平均值
    select sum(score) as sumvalue from user    获取表 user 中字段 score 的总分数
     
    select max(score) as maxvalue from user  获取表 user 中字段 score 的最大值
     
    select min(score) as minvalue from user 获取表 user 中字段 score 的最小值
    select distinct(age) as 年龄 from user_ext  获取表 user_ext 中所有不同的字段 age 并设置字段别名为'年龄'
    select * from user_ext order by weight desc  获取表 user_ext 中的所有数据并且按照字段 weight 进行倒序排序
    SELECT t1.id, t1.students, t2.age, t2.weight FROM user AS t1 LEFT JOIN user_ext AS t2 ON t2.id = t1.id WHERE t2.age > 9;
    通过左连接 获取表 user(别名t1) 和表 user_ext(别名t2) 中字段 id 相同的数据,其中字段 age 大于9,并仅返回 id、students、age、weight 这几个字段的数据
    INSERT INTO user(students,score,gender)  VALUES ('小牛', 100,'男')   在 user 表 所有字段 中添加记录
    update user set score = 30 where students = '小明'   把 user 表 中字段 students 为'小明' 所在字段 score 更改为30分
    delete from user where students = '小马'  把 user 表 students 字段为'小明'的记录删除
    create table test (id integer primary key,students varchar(8),score integer,gender varchar(2)) 
    创建一个名为'test'的表
    drop table user  把'user'表 删除
  • 相关阅读:
    Transcation And Lock--SQL SERVER 事务隔离级别
    Transaction And Lock--常用的查询事务和锁的语句
    使用shell读取文本文件发送到kafka
    VIM打开shell脚本中文乱码解决
    shell中日期操作
    oozie常见错误问题
    error: No implicit Ordering defined for Any
    启动mysql时显示:/tmp/mysql.sock 不存在的解决方法
    mysql中创建用户和赋权限
    (转)maven3.3.9编译oozie4.3.0
  • 原文地址:https://www.cnblogs.com/marksir/p/11685289.html
Copyright © 2011-2022 走看看