zoukankan      html  css  js  c++  java
  • MYSQL查询练习 1

    -- 查询练习 1------------

    CREATE TABLE stu (
    sid CHAR(6),
    sname VARCHAR(50),
    age INT,
    gender VARCHAR(50)
    );
    
    INSERT INTO stu VALUES('S_1001', 'liuYi', 35, 'male');
    INSERT INTO stu VALUES('S_1002', 'chenEr', 15, 'female');
    INSERT INTO stu VALUES('S_1003', 'zhangSan', 95, 'male');
    INSERT INTO stu VALUES('S_1004', 'liSi', 65, 'female');
    INSERT INTO stu VALUES('S_1005', 'wangWu', 55, 'male');
    INSERT INTO stu VALUES('S_1006', 'zhaoLiu', 75, 'female');
    INSERT INTO stu VALUES('S_1007', 'sunQi', 25, 'male');
    INSERT INTO stu VALUES('S_1008', 'zhouBa', 45, 'female');
    INSERT INTO stu VALUES('S_1009', 'wuJiu', 85, 'male');
    INSERT INTO stu VALUES('S_1010', 'zhengShi', 5, 'female');
    INSERT INTO stu VALUES('S_1011', 'xxx', NULL, NULL);

    ----------查询性别为女,并且年龄大于等于50的记录----------


    SELECT * FROM stu WHERE gender='female' AND age>=50

    ----------查询学号为S_1001,或者姓名为liSi的记录----------


    SELECT * FROM stu WHERE sid='S_1001' OR sname='liSi'

    --  查询学号为S_1001,S_1002,S_1003的记录


    SELECT * FROM stu WHERE sid='S_1001' OR sid='S_1002' OR sid='S_1003'

    --  查询学号不是S_1001,S_1002,S_1003的记录


    SELECT * FROM stu WHERE NOT (sid='S_1001' OR sid='S_1002' OR sid='S_1003')

    --  查询年龄为null的记录


    SELECT * FROM stu WHERE age IS NULL

    --  查询年龄在20到40之间的学生记录


    SELECT * FROM stu WHERE age BETWEEN 20 AND 40

    --  查询性别非男的学生记录


    SELECT * FROM stu WHERE gend er!='male'

    --  查询姓名不为null的学生记录


    SELECT * FROM stu WHERE NOT sname IS NULL

    --  查询姓名由5个字母构成的学生记录


    SELECT * FROM stu WHERE sname LIKE '_____'

    --  查询姓名由5个字母构成,并且第5个字母为“i”的学生记录


    SELECT * FROM stu WHERE sname LIKE '____i'

    --  查询姓名以“z”开头的学生记录


    SELECT * FROM stu WHERE sname LIKE 'z%'

    --  查询姓名中第2个字母为“i”的学生记录


    SELECT * FROM stu WHERE sname LIKE '_i%'

    --  查询姓名中包含“a”字母的学生记录


    SELECT * FROM stu WHERE sname LIKE '%a%'

  • 相关阅读:
    flume杀掉重启
    Tomcat访问日志浅析 (转)
    httpclient Accept-Encoding 乱码
    解决Maven报Plugin execution not covered by lifecycle configuration
    mahout基于Hadoop的CF代码分析(转)
    hadoop Mahout中相似度计算方法介绍(转)
    nginx配置文件结构,语法,配置命令解释
    nginx 中文和英文资料
    使用异步 I/O 大大提高应用程序的性能
    nginx AIO机制与sendfile机制
  • 原文地址:https://www.cnblogs.com/pwj-StudyCode/p/11564459.html
Copyright © 2011-2022 走看看