1简单查询   select* from 表名

select name as“姓名”fromstu     (把name改为名字)

2条件查询 where 后面跟条件  条件要写清楚

3模糊查询  like  no like    %代表任意多个字符   _代表一个字符

4排序查询  order by 字段 排序值 (desc降 asc升)

5范围查询     between....and...

6离散查询  in  notin

7聚合查询   sun 求和   count数据条数   max最大值  min最小值 avg平均值

8分页查询 limit 从第几条开始,取多少数据

表名limit(pagesize-1)*5,5     pagesize是页数   *5 是每页条数 ,5 取多少条

9去重查询 distinct      select distinct  表段名 from 表名

10分组查询 group by 字段  having 条件

select count(*),cno,group_concat(degree),sum(degree) from score group by cno ;

select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3

#分组之后根据条件查询使用having 不使用where

高级查询

  1. 连接查询,对列的扩展

Select * from student as stu,score as sc

where stu.sno = sc.sno and sc.sno = “103” ;

2.联合查询,对行的扩展

select Code,Name from Info

union

select Code,Name from Nation

3.子查询

(1)无关子查询

外层查询 (里层查询)

子查询的结果当做父查询的条件

子查询:select Code from Nation where Name='汉族'

父查询:select * from Info where Nation = ''

select * from Info where Nation = (select Code from Nation where Name='汉族')

(2)相关子查询

查询汽车表中油耗低于该系列平均油耗的所有汽车信息

父查询:select * from Car where Oil<(该系列平均油耗)

子查询:select avg(Oil) from Car where Brand = '某个系列'

select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand )

mysql 查询条件的更多相关文章

  1. mysql 查询条件中文问题

    这是mysql字符编码的问题,因为mysql默认的字符编码为latin1它并不识别中文,所以在读取查询语句时会出现乱码 从而使查询条件不正确所以我们只需要更改它的字符编码就可以一般都是用utf8 这里 ...

  2. 字符串变量作mysql查询条件

    原文:http://blog.csdn.net/qing_gee/article/details/41646503 当你的查询条件是一个字符串变量时,你该怎么办,比如字符串可能是“0001ME,000 ...

  3. 转!!mysql 查询条件不区分大小写问题

    做用户登录模块时,输入用户名(大/小写)和密码 ,mysql都能查出来.-- mysql查询不区分大小写. 转自 http://blog.csdn.net/qishuo_java/article/de ...

  4. mysql 查询条件 默认不区分大小写

    mysql查询默认是不区分大小写的 如: 1 2 select * from some_table where str=‘abc'; select * from some_table where st ...

  5. mysql 查询条件不区分大小写问题

    转自 http://blog.csdn.net/qishuo_java/article/details/40118937 转自 https://www.cnblogs.com/wuyun-blog/p ...

  6. Mysql 查询条件中字符串尾部有空格也能匹配上的问题

    一.表结构 TABLE person id name 1 你 2 你(一个空格) 3 你(二个空格) 二.查询与结果 select * from person where `name` = ? 无论 ...

  7. 字符串型MySQL查询条件需要注意的一点

    最近在工作中遇到了数据库服务器产生很多读写队列的问题,于是要求大家开始优化我们的SQL语句. 下面是查询quotedata_history表中的code字段的SQL语句,其中code字段的类型是var ...

  8. mysql查询条件字段值末尾有空格的问题

    mark MYSQL的binary解决mysql数据大小写敏感问题的方法

  9. mysql 关联条件与查询(过滤)条件

    mysql用outer join时 on 后边只是关联条件,有时可能会查出无用的记录, 需用where查询条件过滤 五欧诺个的数据. 记录一下

随机推荐

  1. 02——微信小程序官方demo讲解——app部分

    第一节讲了目录结构,这节主要讲解下目录中app.js部分. 它由三部分组成app.js.app.json与app.wxss 1.JS部分 1.1概述 //app.js App({ onLaunch: ...

  2. javscript踩过的坑 - 记录

    1. js中, ‘==’ 运算符是对大小写敏感的

  3. linux下安装mysql后 sql区分大小写

    Linux下的MySQL默认是区分表名大小写的,通过如下设置,可以让MySQL不区分表名大小写:1.用root登录,修改 /etc/my.cnf:2.在[mysqld]节点下,加入一行: lower_ ...

  4. C# 在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke [问题点数:40分

    注意:  this.DateTimeRun = true;            new Thread(jishi_kernel).Start(); 线程的启动,不能放在    public Form ...

  5. leetcode334

    public class Solution { public bool IncreasingTriplet(int[] nums) { var len = nums.Length; ) { retur ...

  6. nginx实现多个域名共享80端口

    server { listen 80; server_name server8085.duchong.cn; location / { proxy_pass http://127.0.0.1:8085 ...

  7. IDEA debug

    版权声明: 本文转自:https://blog.csdn.net/qq_27093465/article/details/64124330 1,rerun XXX,这个就是直接重新跑某个程序.2,这个 ...

  8. C# unsafe模式内存操作深入探索

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...

  9. JDBC中,如何动态的设置查询条件

    今天看JDBC,发现有段代码,可以减少重复的编写查询方法,如下: public List<Goddess> query(List<Map<String, Object>& ...

  10. CodeFirst(反射+特性)

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...