简体   繁体   中英

How to extract the year from a numeric string using Sql/Presto?

Hello I'm using SQL through Presto and I am trying to extract the year from the numeric string below and some how group the strings so I can pull by year and not month. The string is not stored as a date, its stored as a number. The below reads January 2019.

201901

Just divide by 100:

select floor(num / 100) as year

Note: Presto does integer division. So if the "number" value is an integer, you can just use:

select num / 100 as year

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM