0

I have a query

SQL Query SELECT YEAR(created_At) [YEAR], MONTH(created_at) [MONTH], COUNT(*) as Published_Articles FROM dbo.tasks GROUP BY YEAR(created_At), MONTH(created_at)

Which produces correct result when asked to run in Management Studio

Result

enter image description here

However, when I try to run the same query in laravel tinker, it doesn't run and it says year as an invalid column name but if you look at the query I am using correct alias. Not sure where I am going wrong and why it cannot output the same result as SQL Server Management studio.

tinker not accepting Alias

enter image description here

Can someone please give some direction, I am bit confused

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
  • Group by can’t use result column aliases. As you can see from the working query it’s the actual function that’s used in the grouping, not a column alias – Sami Kuhmonen Oct 22 '18 at 10:58
  • Hi, for some reason the alias are working for Laracast guys, please have a look at the snip of the video where they use Alias https://imgur.com/a/xGwsoMp – hoch_london Oct 22 '18 at 13:09

0 Answers0