Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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_Sql_Database_Rdbms - Fatal编程技术网

mysql更改筛选器的列

mysql更改筛选器的列,mysql,sql,database,rdbms,Mysql,Sql,Database,Rdbms,这是我的问题 select op.*,o.customers_name from orders_payment op, ".TABLE_ORDERS. " o where op.orders_id=o.orders_id AND o.customers_id='".$customers['customers_id']."' AND op.confirm_payment='1' AND (received_date BETWEEN '".$fromdate."' AND '".$t

这是我的问题

    select op.*,o.customers_name from orders_payment op, ".TABLE_ORDERS. " o where op.orders_id=o.orders_id  AND 
o.customers_id='".$customers['customers_id']."' 
AND op.confirm_payment='1' 
AND (received_date BETWEEN '".$fromdate."' AND '".$todate."') order by pay_id desc
我想在这里修改的是“付款日期”列过滤器。如果此列为空,则将其替换为“付款日期”,否则保持不变。 我尝试了一个switch语句,但没有成功。
提前感谢

一种方法使用案例:

((received_date BETWEEN (case when '".$fromdate."' = '' then pament_date else '".$fromdate."' end) AND '".$todate."') or
 (payment_date BETWEEN (case when '".$fromdate."' = '' then pament_date else '".$fromdate."' end) AND '".$todate."')
)

在此过程中,我强烈建议您使用参数范围,而不是使用SQL字符串。至少,您可以传入
NULL
并使用
coalesce()
而不是
case

一种方法使用
case

((received_date BETWEEN (case when '".$fromdate."' = '' then pament_date else '".$fromdate."' end) AND '".$todate."') or
 (payment_date BETWEEN (case when '".$fromdate."' = '' then pament_date else '".$fromdate."' end) AND '".$todate."')
)
在此过程中,我强烈建议您使用参数范围,而不是使用SQL字符串。至少,您可以传入
NULL
并使用
coalesce()
而不是
case