TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Agarwal
NA
379
254.2k
Date sorting issue in sql server
Feb 15 2018 4:15 AM
Hello,
I want to display date, according to last updated but my date sorting is wrong.
I need to Result:-
Months Request
February 18 4
January 18 60
December 17 32
November 17 7
when i tried:-
select FORMAT(CreatedDateTime,'MMMM yy') as Months, count(*) as Request from LRequests
group by FORMAT(CreatedDateTime,'MMMM yy')
order by FORMAT(CreatedDateTime,'MMMM yy') DESC
so data displaying:
Months Request
November 17 7
January 18 60
February 18 4
December 17 32
then when i tried:-
select FORMAT(CreatedDateTime,'MMMM yy') as Months, count(*) as Request from LRequests
group by FORMAT(CreatedDateTime,'MMMM yy')
order by CreatedDateTime DESC
Getting error:-
Column "LRequests.CreatedDateTime" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
Please help me.
Thanks in Advance.
Ankit Agarwal
Software Engineer
Reply
Answers (
2
)
SQL query tuning?
OT Calculation based on