查找数据

查找数据

只查找指定的字段:

select id ,usersname from users;

查找数据

 

select users.id,users.username from users;针对多表查询

换名查找

select id as userid,username as uname from user;

查找数据

select id as usersname from users;

查找数据

 条件查找

查找数据

查找数据

查找数据

select sex from users group by sex ;

select sex from users group by 1 ;

对sex栏所有数据结果进行分组;

也可以对对指定的记录进行分组:

查找数据

select sex,age  from users group by 1 having age>35,在所有记录中,在age大于当前条件下,进行分组

主义age也要在select语句里;

select sex from users group by 1 having count(id) >=2;意思是  sex的值为2的有几个?

此处的id出现在聚合函数内

查找数据

 

查找数据

select * from users order by id desc,通过降序排列

select * from users order by age ,age默认升序从小到大排列,

select * from users order by age ,id desc;

查找数据

查找数据

limit3,2的意思是从下标为3(下标从0开始)的记录开始返回,返回2条数据;

查找数据

虽然是降序排列,但是limit里的第一个数和id没有关系,只与数据集里的排列顺序有关

相关文章:

  • 2021-11-30
  • 2022-01-15
  • 2022-02-07
  • 2022-01-05
  • 2022-02-27
  • 2021-07-24
猜你喜欢
  • 2021-11-25
  • 2021-09-19
  • 2022-01-20
  • 2021-08-07
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
相关资源
相似解决方案