我知道 where 子句搜索并根据条件显示记录成真,并且限制用于从表中获取记录数。
但是,当我尝试同时使用它们时,请帮助我。
我有一个包含以下记录的表
表:记录
+---------+--------+------------+
| id | type | Credits |
+---------+--------+------------+
| 1 | my | 100 |
| 2 | my | 200 |
| 3 | other | 50 |
| 4 | my | 500 |
+---------+--------+------------+
Run Code Online (Sandbox Code Playgroud)
有许多不同的此类记录在表中依次排列。
我想按type列获取任何 3 条记录,然后我设计了以下查询!
select * from `records`
where `type` = 'my'
limit 3
Run Code Online (Sandbox Code Playgroud)
我得到了 2 个“my”类型的结果,但是我想跳过其他类型的数据,然后是“my”类型的前 3 条记录
如何使用 mysql 数据库执行此操作。
感谢期待!
小智 2
您需要使用order by credits desc(降序)才能获得 3 个最高学分,因此 sql 将是:
select * from `records`
where `type` = 'my'
order by credits desc
limit 3;
Run Code Online (Sandbox Code Playgroud)