两个类别折叠为1行

时间:2019-01-31 01:15:49

标签: amazon-web-services amazon-redshift

我有两行是这样的:

enter image description here

我想编写一个SQL查询,将两行折叠成这样:

enter image description here

有人对此有想法吗?

1 个答案:

答案 0 :(得分:1)

那会是这样的:

SELECT
  first_name,
  last_name,
  business_name,
  trade,
  date_submit,
  MAX(CASE WHEN insurer = 'Progressive' THEN status END) as status_progressive,
  MAX(CASE WHEN insurer = 'Travelers' THEN status END) as status_travelers
FROM table
GROUP BY first_name, last_name, business_name, trade, date_submit

我没有测试它,但是应该可以给你这个概念。这里没有Amazon Redshift独有的东西。

相关问题