问题:
假设给出了以下dbo.LoanStatements表。该表的所有记录如下所示。每条记录都显示语句的发送时间。
LoanID StatementDate OriginalLoanToValue
-------------------------------------------
1 03/15/2005 0.80
1 04/15/2005 0.90
1 05/15/2005 0.90
1 06/15/2005 0.90
2 08/15/2017 66.7
2 09/15/2017 66.7
2 10/15/2017 0.50
3 10/15/2017 0.66
4 10/15/2017 0.55
编写一个返回的SELECT语句(或多个语句) 以下结果集
1 0.90 2 0.50 3 0.66 4 0.55
尝试解决方案 -
SELECT LoanID, OriginalLoanToValue
FROM LoanStatements
WHERE StatementDate IN (
SELECT MAX(StatementDate)
FROM LoanStatements
GROUP BY LoanID
);
尝试解决方案:
2005
SELECT LoanID,StatementDate,OriginalLoanToValue
FROM LoanStatements
WHERE year(StatementDate) = 2005;
2017
SELECT LoanID,StatementDate,OriginalLoanToValue
FROM LoanStatements
WHERE year(StatementDate) = 2017;
我没有办法检查这段代码是否正确这只是我能想出的一些我知道的SQL,如果有人能澄清这是否正确,我将不胜感激。谢谢!
答案 0 :(得分:0)
如果您的数据类型为“StatementDate”列的“DATE”,“DATETIME”,“TIMESTAMP”,“YEAR”,则您的查询将更正。