Skip to content
Advertisement

Capturing year of a DATE in SQL Worksheet (Datameer)

In Datameer, how do you capture the year of a DATE column in a SQL worksheet?

This query

SELECT YEAR(rslt_part.draw_date) AS YEAR, COUNT(*) AS CT FROM
rslt_part
GROUP BY YEAR

is returning the following error: 

“Encountered ‘AS YEAR’… was expecting one of: “ORDER” … “LIMIT” … “OFFSET” … “FETCH” … “FROM” … “,” … “AS” … “AS” … “AS” … “AS” … “AS” … “UNION” … “INTERSECT” … “EXCEPT” … “MINUS” … “NOT” … “IN” … “<” … “<=” … “>” … “>=” … “=” … “<>” … “!=” … “BETWEEN” … “LIKE” … “SIMILAR” … “+” … “-” … “*” … “/” … “%” … “||” … “AND” … “OR” … “IS” … “MEMBER” … “SUBMULTISET” … “CONTAINS” … “OVERLAPS” … “EQUALS” … “PRECEDES” … “SUCCEEDS” … “IMMEDIATELY” … “MULTISET” … “[” … “FILTER” … “OVER” …”

Advertisement

Answer

Try aliasing the YEAR() call to something other than YEAR, and also try repeating the function call in the GROUP BY clause:

SELECT YEAR(draw_date) AS yr, COUNT(*) AS cnt
FROM rslt_part
GROUP BY YEAR(draw_date)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement