Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择行,直到列值为';不一样_Mysql - Fatal编程技术网

Mysql 选择行,直到列值为';不一样

Mysql 选择行,直到列值为';不一样,mysql,Mysql,我想我可能已经修复了它,我把它添加到了我的while循环中 该查询使用日期和时间按从现在到过去的顺序给出结果,而该while循环检查该行的列是否等于“bad”,如果该行正在执行某些操作(可能能够使用数组填充数据)。如果不是,则循环被破坏 我知道这看起来不太理想,但它很有效,哈哈 ProductID Date status 1 2017-03-27 Good 2 2017-03-27 Good 3 2017-03-26 Good 4

我想我可能已经修复了它,我把它添加到了我的while循环中

该查询使用日期和时间按从现在到过去的顺序给出结果,而该while循环检查该行的列是否等于“bad”,如果该行正在执行某些操作(可能能够使用数组填充数据)。如果不是,则循环被破坏

我知道这看起来不太理想,但它很有效,哈哈

ProductID   Date     status
1        2017-03-27  Good
2        2017-03-27  Good
3        2017-03-26  Good
4        2017-03-25  Bad
5        2017-03-25  Good

我将用您的输出提供一个答案,就像它只是一个表一样。它将为你提供解决问题的主要思路

基本上,我创建了一个名为
ord
的列,它将作为一个行号(MySql目前还不支持它)。然后我得到了一个坏状态的最小值,然后我从数据中得到了所有数据,其中
ord
小于这个值

   while ($row = mysqli_fetch_assoc($result)) {
    if ($row['status'] == "bad") {
    $counter += 1;
    }
    else{
break;}
还使用
Bad
状态为第一个结果的用例进行测试,不会返回任何结果


查看此处的工作状态:

好状态和坏状态是否可能具有相同的日期和时间?那么优先级应该是什么呢?@JorgeCampos Nope这是不可能的,因为shelf.expire对每一行都是不同的伟大的答案,但是如果没有坏的cols,如何返回所有的行呢?目前,如果没有不良状态,它不会返回任何行。您好@DavidGlass我认为您可以代替
where
子句,将其作为左连接添加到
from
部分,这可能会起作用。如果没有,你可以添加一个关于它的问题。
   while ($row = mysqli_fetch_assoc($result)) {
    if ($row['status'] == "bad") {
    $counter += 1;
    }
    else{
break;}
select y.* 
  from (select ProductID, dt, status, @rw:=@rw+1 ord
          from product, (select @rw:=0) a
         order by dt desc) y
 where y.ord < (select min(ord) ord
                  from (select ProductID, status, @rin:=@rin+1 ord
                          from product, (select @rin:=0) a
                         order by dt desc) x
                 where status = 'Bad');
ProductID        dt     status  ord
-------------------------------------
1           2017-03-27   Good    1
2           2017-03-27   Good    2
3           2017-03-26   Good    3