我想从按party_id分组的表中获取或获取最大日期。
要做到这一点,我试过:
$check = mysql_fetch_array(mysql_query("select max(fixed_date) as f from case_proceeding group by party_id where party_id='$row[party_id]'"));
之后,我想打印这样的最大日期:
echo $check['f'];
但它不起作用。我认为mysql_query中有一个错误。
答案 0 :(得分:0)
尝试,因为您已经从GROUP BY
过滤了<{1}}
WHERE
(应该在WHERE
子句之后)
$check = mysql_fetch_array(mysql_query("select max(fixed_date) as f from case_proceeding where party_id='$row[$party_id]'"));
但SQL Injection
您的问题很容易受到攻击,请阅读以下文章以防范它
答案 1 :(得分:0)
试试这个:
此处不需要GROUP BY子句
select max(fixed_date) as f
from case_proceeding
where party_id='$row[party_id]
答案 2 :(得分:0)
试试这个::
select max(DATE(fixed_date)) as f from case_proceeding where party_id=? group by party_id
答案 3 :(得分:0)
试
$check = mysql_fetch_array(mysql_query("select max(fixed_date) as f from case_proceeding where party_id='$row[party_id]' "));
注意:不推荐使用mysql_ *函数,所以请尝试使用pdo或mysqli