答案 0 :(得分:1)
试试这个。
dateDf$ReagentType <- typeDf$ReagentType[as.numeric(cut(dateDf$Date,
breaks = typeDf$Date))]
对于动态查询月和年
SELECT * FROM (SELECT
SUM(Cost) AS Cost,
CONVERT(VARCHAR(3), DATENAME(MONTH, DATEADD(MONTH, MONTH(MonthCol), - 1))) MonthCol
FROM myTable WHERE YEAR(MonthCol) = 2016
GROUP BY MonthCol) AS TP
PIVOT (SUM(Cost) FOR MonthCol IN ([Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec])) AS PVTTable