我需要跟踪访问者在我的网站上,所以我使用这个存储过程,但它没有给我想要的结果,任何人都可以帮助我。 我需要一月最后.....我的意思后,十二月SQL Server存储过程(需要最近5个月onlly)
Select A.TotalPerMonth , DateName(month , DateAdd(month , A.monthValue , -1)) as month , A.Year
from(Select Top 5 count(pk_id) as TotalPerMonth,
month(VistorDate) as monthValue,
Year(VistorDate) as Year
from jot.tbl_vistor
group by month(VistorDate) ,YEAR((VistorDate))
order by YEAR((VistorDate)) desc) A order by A.monthValue , A.Year ASC
以下是结果,我需要的月份每月最后,但在前面
说明期望: 我需要前5九月,十月,十一月,十二月,一月.....意味着过去的5月,当新的记录fabruary被发现,就会丢弃月
ORDER BY年,月 – wiretext
@tinka使用后,我没有12月的价值,但一月是最后,我确实选择top 5 –
你应该更好地描述你想要的结果是什么..给我们一个正确顺序的例子。 – tobypls