我希望缩小数据库范围,以仅保留最多记录。最新记录需要在特定字段中具有值。
ID Account_nbr Date Name
1 622 7/10/2018 Stu
2 622 7/24/2018
3 151 7/18/2018 Taylor
4 151 7/24/2018 Taylor
这是数据库的示例。 我希望代码执行此操作:
ID Account_nbr Date Name
1 622 7/10/2018 Stu
4 151 7/24/2018 Taylor
我尝试了以下代码:
Select m.*
FROM [table] m
INNER JOIN
(
SELECT last(Date) as LatestDate
,account_nbr
FROM [table]
WHERE Name IS NOT NULL
GROUP BY account_nbr
) b
ON m.Date = b.LatestDate
AND m.account_nbr = b.account_nbr
输出仅包含最近的日期,而未考虑名称字段中为空的记录。
答案 0 :(得分:1)
我会做的:
// Set a simple Footer including the page number
$mpdf->setFooter('{PAGENO}');
$mpdf->WriteHTML('Section 1');$mpdf->WriteHTML('');
// You could also do this using
// $mpdf->AddPage('','','','','on');
$mpdf->WriteHTML('Section 2 - No Footer');
$mpdf->WriteHTML('<pagebreak resetpagenum="1" pagenumstyle="i" suppress="off" />');
$mpdf->WriteHTML('Section 3 - Starting with page a');
$mpdf->Output();
答案 1 :(得分:0)
尝试一下:
Select
m.*
From
[table] As m
Where
m.[Date] In
(Select Max([Date])
From [table] As T
Where T.[Name] Is Not Null
And T.account_nbr = m.account_nbr)