选择大于和直到的位置

时间:2018-12-31 05:18:35

标签: mysql database

我被困于获取关于select大于和直到的结果 例如,这是我的数据

id    profile_id    status     created_at                   updated_at
1         1           2        31/12/2018  03.38.02   31/12/2018  03.38.02
2         1           4        01/01/2019  03.38.02   01/01/2019  03.38.02
3         1           2        02/01/2019  03.38.02   02/01/2019  03.38.02
4         1           4        03/01/2019  03.38.02   03/01/2019  03.38.02
5         1           5        03/01/2019  03.38.02   03/01/2019  03.38.02
6         1           4        03/01/2019  03.38.02   03/01/2019  03.38.02

我想要这样的结果,并且行在上一个状态= 4之前显示所有值,直到满足状态4

 5         1           5        03/01/2019  03.38.02   03/01/2019  03.38.02
 6         1           4        03/01/2019  03.38.02   03/01/2019  03.38.02

现在,我已经尝试过这种方法,但是没有成功,像这样的查询

SELECT 
  * 
FROM
  `profiles` 
WHERE `created_at` > 
  (SELECT 
    `created_at` 
  FROM
    `profiles` 
  WHERE `status` IN ('4') 
    AND `profile_id` = '1'
  ORDER BY `from` DESC 
  LIMIT 1) 
  AND `profile_id` = '1'
  AND `status` IN (0, 1, 2, 3, 4, 5) 
ORDER BY `from` ASC 

结果为空

如果我这样修改数据

id    profile_id    status     created_at                   updated_at
1         1           2        31/12/2018  03.38.02   31/12/2018  03.38.02
2         1           4        01/01/2019  03.38.02   01/01/2019  03.38.02
3         1           2        02/01/2019  03.38.02   02/01/2019  03.38.02
4         1           4        03/01/2019  03.38.02   03/01/2019  03.38.02
5         1           5        03/01/2019  03.38.02   03/01/2019  03.38.02
*6         1           2        03/01/2019  03.38.02   03/01/2019  03.38.02*

还有这样的查询结果

 5         1           5        03/01/2019  03.38.02   03/01/2019  03.38.02
 6         1           2        03/01/2019  03.38.02   03/01/2019  03.38.02

当然,我期望的结果不是这样,我希望结果不修改正在显示的先前数据

 5         1           5        03/01/2019  03.38.02   03/01/2019  03.38.02
 6         1           4        03/01/2019  03.38.02   03/01/2019  03.38.02

任何人都可以帮助我解决这个问题吗?

0 个答案:

没有答案