【问题标题】:removing duplicate values and null postgresql删除重复值和空 postgresql
【发布时间】:2022-11-02 22:24:10
【问题描述】:
with res as(select us.column,mg.column as status,count(mg.column)  FROM Table_name1 it
LEFT JOIN   Table_name2 us on it.column=us.column
LEFT JOIN   Table_name3 mg on it.column=mg.column
where it.column   is not null and it.column in(5,6) and (it.column + '05:30:00'::INTERVAL)::date between '2022-08-28' and '2022-10-03'  group by us.column,mg.column)
select res.column,
(case when column='Open' then count end) as Open_status,
(case when column='Closed' then count end) as Closed_status
from res  group by res.column,res.column,res.column

我需要解决第 1 列中的删除重复条目打开和关闭时打开和关闭状态计数详细信息显示以及当它关闭打开详细信息时显示特定人

【问题讨论】:

    标签: postgresql


    【解决方案1】:
    -- Make new complete entries from any incomplete entries
    INSERT INTO duplicated
         SELECT first_name
              , max(open_status)
              , max(closed_status)
           FROM duplicated
          WHERE open_status IS NULL OR closed_status IS NULL
          GROUP BY first_name
    ;
    -- Remove the incomplete entries leaving only complete entries
    DELETE
      FROM duplicated
     WHERE open_status IS NULL OR closed_status IS NULL
    ;
    

    【讨论】:

    • 如何在加入时执行相同的过程以及在相同条件下打开和关闭时如何执行
    • 我不明白你的问题。
    【解决方案2】:

    SELECT table1.first_name, table1.last_name, table2.open_status, (CASE WHEN CONCAT(table1.first_name, table1.last_name) = '' THEN table2.open_status ELSE CONCAT_WS(' ', table1.open_status, table1.closed_status) END) AS Status, FROM table1 JOIN table2 ON table1.user_id = table2.user_id JOIN table3 ON table2.partner_id = table3.id GROUP BY table1.first_name, table1.last_name, table2.copmany_name, (CASE WHEN CONCAT(table1.first_name, table1.last_name) = '' THEN table2.open_status ELSE CONCAT_WS(' ', table1.first_name, table1.last_name) END) AS name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-23
      • 2017-02-17
      • 2014-11-11
      • 2019-06-22
      • 2015-03-11
      • 1970-01-01
      • 2016-08-16
      • 2022-01-12
      相关资源
      最近更新 更多