Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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
Distinct在MySQL的过程中不起作用 如果(eventType=1),则 设置@Whereclause=CONCAT(@Whereclause,“and scheduleDate>”,@currentdate,“order by scheduleDate”); 如果结束; 如果(eventType=0),则 设置@Whereclause=CONCAT(@Whereclause,“和scheduleDate_Mysql_Sql - Fatal编程技术网

Distinct在MySQL的过程中不起作用 如果(eventType=1),则 设置@Whereclause=CONCAT(@Whereclause,“and scheduleDate>”,@currentdate,“order by scheduleDate”); 如果结束; 如果(eventType=0),则 设置@Whereclause=CONCAT(@Whereclause,“和scheduleDate

Distinct在MySQL的过程中不起作用 如果(eventType=1),则 设置@Whereclause=CONCAT(@Whereclause,“and scheduleDate>”,@currentdate,“order by scheduleDate”); 如果结束; 如果(eventType=0),则 设置@Whereclause=CONCAT(@Whereclause,“和scheduleDate,mysql,sql,Mysql,Sql,,则我们必须在选择列表中按列排序,如下所示: 任一: if(eventType=1 ) then set @Whereclause=CONCAT(@Whereclause," and scheduleDate > ",@currentdate, " order by scheduleDate " ); end if; if(eventType=0 ) then set @Whereclause=CONCAT(@Whereclause,"

,则我们必须在选择列表中按列排序,如下所示:

任一

    if(eventType=1  ) then
     set @Whereclause=CONCAT(@Whereclause," and  scheduleDate > ",@currentdate, " order by  scheduleDate " );
    end if;
     if(eventType=0  ) then
     set @Whereclause=CONCAT(@Whereclause," and  scheduleDate < ",@currentdate," order by  scheduleDate  desc " );
    end if;
     if(eventType=-1 ) then 
      set @Whereclause=CONCAT(@Whereclause," order by  scheduleDate  desc  " );
      end if;

   set @SqlQuery=  CONCAT("
select   distinct(event_schedule_id)
 from TEST_EVENT_LIST_VIEW ", @Whereclause );


set totalcountquery=@Whereclause;

  if(offsetvalue<recordlimit) then  

      set @QueryfforPagination=CONCAT(@SqlQuery," limit ",recordlimit );
     PREPARE querystatement FROM @QueryfforPagination;
     EXECUTE querystatement;
     DEALLOCATE PREPARE querystatement;


    else 
       set  @QueryfforPagination=CONCAT(@SQLQuery," limit ",recordlimit," offset ",offsetvalue);
       PREPARE querystatement FROM @QueryfforPagination;
       EXECUTE querystatement;
       DEALLOCATE PREPARE querystatement;

    end if;


END

 order by  event_schedule_id desc

如果我们从上面删除DISTINCT,那么所有语句都可以正常工作。

如何修复?首先,您必须弄清楚您想要什么。。。
set @SqlQuery=  CONCAT("
select   distinct event_schedule_id, scheduleDate
from TEST_EVENT_LIST_VIEW ", @Whereclause );

SELECT DISTINCT A FROM myTable ORDER BY B --It doesn't work
SELECT DISTINCT A FROM myTable ORDER BY A --It works
SELECT DISTINCT A, B FROM myTable ORDER BY A, B --It works
SELECT DISTINCT A, B FROM myTable ORDER BY B --It works