从删库到跑路(2)

1- 查询整张表的所有数据:

 SELECT * FROM myfirst_schema.pets;

如果当前表的数据比较多,只想看到特定行的数据:

select * from pets where name='shagou';

在上面这个查询语句中,可以制定任何列为条件:

select species from pets where birthday>='2018-10-31' and name='shagou';

这里是用了一个逻辑运算符‘and’,还有一个‘or’运算符

select species from pets where birthday>='2018-10-31' or name='shagou';

‘and’ 和 'or’可以混合使用,但是and优先级高于or,如果你像同时使用这两个运算符,最好使用括号明确指出如何分组

select owner from pets where (name='shagou' and sex='m')or(name='phili'and sex='f');

2- 排序行
对表数据按照某种有意义的方式排序,通常更容易检查查询结果。要对结果进行排序使用ORDER BY 子句。这种排序方式默认是升序,若要反向排序,则需要加关键字DESC
查询结果按照升序:select name, birthday from pets order by birthday;
降序: select name, birthday from pets order by birthday DESC;

也可以对多个列进行排序,并且可以按不同方向对不同的列及逆行排序
例如,要按动物类型按升序排序,然后按动物类型中的出生日期按降序排序(最年轻的动物首先):select name, species,birthday from pets order by species,birthday desc;该DESC关键字仅适用于紧邻其前面的列名(birthday); 它不会影响species列排序顺序。`

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值