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 出版社;

  • 相关阅读:
    正则表达式 ^
    jQuery的加法运算,val()获取的结果相加变成了字符串连接。
    mssql 取数据指定条数(例:100-200条的数据)
    css样式大全(整理版)
    50个技巧提高你的PHP网站程序执行效率
    ASP版_阿里大于短信API Demo
    FusionCharts的使用方法(超详细)
    FusionCharts参数说明 (中文)
    web服务器选择Apache还是Nginx
    反向代理服务器的工作原理
  • 原文地址:https://www.cnblogs.com/lsxsx/p/13388029.html
Copyright © 2011-2022 走看看