我想知道是否可以获取上个月的记录吗?例如,如果运行了以下查询,则该查询应提供2019年1月4日至2019年4月30日(4月1日至4月30日)之间的交易输出。
select * from table where transdate>='01-01-2019' and transdate <='31-05-2019'
Sample data
TRANSDATE LABOR Hours
01-01-2019 A 2.5
23-01-2019 B 1.0
01-02-2019 B 3.0
12-03-2019 A 0.5
02-04-2019 A 1.5
12-04-2019 B 4.5
17-04-2019 B 2.0
22-04-2019 C 2.5
12-05-2019 A 3.5
Expected Output
TRANSDATE LABOR Hours
Apr-2019 A 1.5
Apr-2019 B 6.5
Apr-2019 C 2.5
答案 0 :(得分:0)
如果public class AuthHandler : IAuthHandler
{
public IDictionary<string, DateTime> Activity;
public IDictionary<string, string> Accounts;
public AuthHandler()
{
Activity = new Dictionary<string, DateTime>();
Accounts = new Dictionary<string, string>();
}
public KeyValuePair<string, string> Generate()
{
var bestAccount = Accounts.Where(x => !Activity.ContainsKey(x.Key)).FirstOrDefault();
Activity[bestAccount.Key] = DateTime.Now;
return bestAccount;
}
}
是根据用户输入(例如last previous month
)计算的,则:
2019-05-31
用户可以提供每月的任何日期。 select to_char(TRANSDATE, 'Mon-YYYY', 'en-US') as TRANSDATE, LABOR, sum(Hours) as Hours
from table
where transdate between
date('2019-05-31') - (day(date('2019-05-31')) - 1) days - 1 month
and date('2019-05-31') - day(date('2019-05-31')) days
group by to_char(TRANSDATE, 'Mon-YYYY', 'en-US'), LABOR
;
子句中表达式的结果对于同一月的任何提供的日期都是相同的。