为SQL中同一列上的不同where子句获取多个列

问题描述 投票:0回答:1

我有一个包含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

我的输出是这个

enter image description here

对我来说,除了2020年以外,还有一列叫2019年,它提供的数据与2019年的2020年相同。

如果我有强调的地方,请在评论中让我知道。

sql where-clause calculated-columns having
1个回答
0
投票
Select Count(Year(year_col)) as year, Pin_code From T Group_by pin_code Order by pin_code desc;
© www.soinside.com 2019 - 2024. All rights reserved.