我有一个包含date
的表和列(以字符串表示)。我需要从同一日期列中获取两列,例如countin(2020)
和countin(2019)
,以便日期类似于'2020%'或'2019%',我希望将它们作为单独的列。
我的查询有点像。
select C.pin_code,count(distinct(C.customer_code)) as 2020 from table group by C.pin_code
我的输出是这个
对我来说,除了2020年以外,还有一列叫2019年,它提供的数据与2019年的2020年相同。
如果我有强调的地方,请在评论中让我知道。
Select
Count(Year(year_col)) as year,
Pin_code
From T
Group_by pin_code
Order by pin_code desc;