我有这样的查询
SELECT
A.JBCo, A.Invoice, MAX(B.JCDate) AS LastWorkedDay, C.Description
FROM
C
INNER JOIN A ON
C.JBCo = A.JBCo AND
C.BillMonth = A.BillMonth AND
C.BillNumber = A.BillNumber
INNER JOIN B ON
C.JBCo = B.JBCo AND
C.BillMonth = B.BillMonth AND
C.BillNumber = B.BillNumber AND
C.Line = B.Line
GROUP BY
A.Invoice, A.JBCo, C.Description
HAVING
(A.JBCo = 12) AND
(A.Invoice LIKE '%1000223%')
得到类似的结果
Co invoice Lastworkdate description
12 1000223 2012-12-9 Labor
12 1000223 2012-12-7 Equipment
12 1000223 2012-12-2 Material
我需要一个查询来产生类似“劳动力”的结果,然后在劳动力中使用 lastWorkedDate,如果发票中没有劳动力,则使用最后日期。所以最终结果将只有每张发票的一行,在这种情况下将是(无需显示描述)。我尝试使用 case when 语句,但我无法正确使用它。请帮忙。谢谢
12 1000223 2012-12-09