在这个伟大的article
中,我找到了将年转换为十年的方法,但它对我来说太过冗长了!
有更好的方法吗?
{!! Form::number('preco', null, ['class' => 'form-control','step' => '0.1']) !!}
答案 0 :(得分:1)
从年份“提取”十年 - REGEXP_REPLACE
功能可以在下面的示例中使用
#standardSQL
WITH data AS (
SELECT '1921' AS YEAR UNION ALL
SELECT '1932' UNION ALL
SELECT '1943' UNION ALL
SELECT '1954' UNION ALL
SELECT '1985' UNION ALL
SELECT '2006' UNION ALL
SELECT '2017' UNION ALL
SELECT '2018'
)
SELECT
YEAR,
CASE
WHEN YEAR LIKE "192%" THEN "20S"
WHEN YEAR LIKE "193%" THEN "30S"
WHEN YEAR LIKE "194%" THEN "40S"
WHEN YEAR LIKE "195%" THEN "50S"
WHEN YEAR LIKE "196%" THEN "60S"
WHEN YEAR LIKE "197%" THEN "70S"
WHEN YEAR LIKE "198%" THEN "80S"
WHEN YEAR LIKE "199%" THEN "90S"
WHEN YEAR LIKE "200%" THEN "2000S"
WHEN YEAR LIKE "201%" THEN "2010S"
END AS DECADES
FROM data
-- ORDER BY YEAR