zoukankan      html  css  js  c++  java
  • mysql 查询

    查询所有列

    SELECT * FROM student;

    查询指定列

    SELECT Accounts,Detauks,Date from  guest;

    查询时添加常量列

    需求:在查询guest时添加酒店列内容为‘七天酒店‘

    SELECT Accounts,Detauks,Date,'七天酒店' as'酒店'from  guest;

    查询时合并列

    select id,name,(servlet+jsp)as'总成绩'from STUDENT;

    和并列只能合并数值类型的列

    查询时去除重复的记录

    select  distinct accounts from guest; 

    另一种语法 

    select  distinct (accounts) from guest; 

    查询酒店有收入的日期

    select DISTINCT (DATE) FROM GUEST;

    条件查询(where)

    逻辑条件: and()     or()

    查询账号为 s001且消费为280 的记录

    select  * FROM WHERE ACCOUNTS = '00'AND MONEY='280';

    比较条件: >   <   >=  <=  =  <>(不等于)     between and (等价于>= <=)

     需求 :查询消费大于100的账号

    Select accounts from guest where money>'100';

    查询 消费金额大于100且小于200的账号 

    select accounts from guest where money>='100'and monet<='200';

    另一张写法

    select * from guest where money between 100and200;//包前包后 

    SELECT * FROM student WHERE gender<>'';//筛选出gender不为男的记录

    判空条件(null 空字符串):  is null / is not null / =''  / <>''

    需求: 查询班次为空的记录(包括null和空字符串)

    select * from guest where Class is null;

    select * from guest where Class is not null;

    select * from guest where Class = '';

    select * from guest where Class <>'';

    - 需求: 查询班次(不包括null和空字符串)

    SELECT *  FROM guest money IS NOT null and money<>''; 

     模糊条件: like

    -- 通常使用以下替换标记:

    -- % : 表示任意个字符

    -- _ : 表示一个字符

    需求:查询编号S开头的账号

    select * from guest where accounts like 's%'; 

    查询房什么的金额;

    select * from guest where detauks like '房_';

  • 相关阅读:
    dotnet core 获取 MacAddress 地址方法
    dotnet core 获取 MacAddress 地址方法
    dotnet core 发布只带必要的依赖文件
    dotnet core 发布只带必要的依赖文件
    Developing Universal Windows Apps 开发UWA应用 问答
    Developing Universal Windows Apps 开发UWA应用 问答
    cmd 如何跨驱动器移动文件夹
    cmd 如何跨驱动器移动文件夹
    C++ 驱动开发 error LNK2019
    C++ 驱动开发 error LNK2019
  • 原文地址:https://www.cnblogs.com/qmk-716/p/9665430.html
Copyright © 2011-2022 走看看