zoukankan      html  css  js  c++  java
  • 数据查询

    mysql-> select * from mysql_test.cust

        -> where cust_sex='M';

    mysql-> select * from mysql_test.cust

        -> where cust_id between 903 and 912;

    mysql-> select * from mysql_test.cust

        -> where cust_id in(903,906,908);

    mysql-> select * from mysql_test.cust

        -> where cust_contact is null;  //is not null

    mysql-> select studentNo,studentName 

        -> from tb_student

        -> where studentNo in(select studentNo from tb_score where score>80);   //通过外键联系起来

    mysql-> select cust_address,cust_sex,count(*) as '人数'   //mysql 5.5版本的group by后面的字段必须和select的字段一致

        ->  from mysql_test.cust

        ->  group by cust_address,cust_sex;

    mysql-> select cust_address,cust_sex,count(*) as '人数'  //汇总

        ->  from mysql_test.cust

        ->  group by cust_address,cust_sex

        ->  with rollup;

    mysql-> select cust_name,cust_address

        ->  from mysql_test.cust

        ->  group cust_name,cust_address

        ->  having count(*)<=3;

    mysql-> select cust_name,cust_sex from mysql_test.cust

        ->  order by cust_name desc,cust_sex desc;

    mysql-> select cust_id,cust_name from mysql_test.cust

        ->  order by cust_id

        ->  limit 4,3;   //默认从0开始 另一种形式: limit 3 offset 4;

    练习:

    (1)   select * from 图书

      where 单价 between 50 and 60

      order by 出版社,单价;

    (2)  select 书名,借阅时间

      from 图书,借阅,读者

      where 姓名='王明' and 读者.借书证号=借阅.借书证号 and 借阅.图书编号=图书.图书编号;

    (3)  select 出版社,max(单价),min(单价),avg(单价)

      from 图书

      group by 出版社;

  • 相关阅读:
    ASP.NET MVC : 实现我们自己的视图引擎
    [转] 理解 JavaScript 闭包
    郁闷的disabled
    ASP.NET MVC 使用Post, Redirect, Get (PRG)模式
    获取窗口 高 、宽 的JS代码
    javaScript 中的return和return false
    一种标记是否为AJAX异步请求的思路
    ASP.NET MVC 源码更新预览
    [译]用Visual Studio2012来开发SQL Server 2012商业智能项目
    玩玩Windows Azure
  • 原文地址:https://www.cnblogs.com/lsxsx/p/13388029.html
Copyright © 2011-2022 走看看