1

我想从按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 有错误。

4

4 回答 4

0

尝试,GROUP BY应该在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,请阅读下面的文章以防止它

于 2012-11-28T06:21:52.110 回答
0

试试这个:

此处不需要 GROUP BY 子句

select max(fixed_date) as f 
from   case_proceeding 
where  party_id='$row[party_id]
于 2012-11-28T06:22:00.220 回答
0

试试这个 ::

select max(DATE(fixed_date)) as f from case_proceeding where party_id=? group by party_id 
于 2012-11-28T06:22:42.780 回答
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

于 2012-11-28T06:23:03.657 回答