一段不知所云的SQL

本文深入探讨了SQL在数据库查询中的应用,分享了高级查询技巧和实际案例,帮助读者提升SQL操作效率和数据处理能力。
摘要由CSDN通过智能技术生成
delete from nash_invoice;
INSERT INTO nash_invoice(
    id,
    invoice_no,
    contract_no,
    contract_type,
    customer_name,
    nash_company,
    opening_type,
    invoice_type,
    invoice_base_info,
    invoice_open_status,
    invoice_other_info,
    created_by,
    confirm_at,
    created_at,
    updated_at,
    invoice_at,
    apply_at,
    housefee_id
) 
SELECT
    t.id,
    invoice_no,
    contract_no,
    contract_type,
    relate_table_name,
    COALESCE(c.company_id,s.company_id) as company_id,
    CASE WHEN pay_type = 1 THEN 1
         WHEN pay_type = 2 THEN 2
         WHEN pay_type = 3 THEN 1
         WHEN pay_type = 4 THEN 2
    END AS opening_type,
    invoice_type AS invoice_type,
    COALESCE(c.invoice_base_info,s.invoice_base_info) as invoice_base_info,
    CASE WHEN state = 3 THEN 3
    END AS invoice_open_status,
    w.invoice_other_info,
    create_user_id AS created_by,
    CASE WHEN confirm_date = '' THEN NULL
        WHEN confirm_date = '0000-00-00' THEN NULL
        ELSE confirm_date :: TIMESTAMP
        END AS confirm_at,
    CASE WHEN pass_time = '' THEN NULL
        WHEN pass_time = '0000-00-00 00:00:00' THEN NULL
        ELSE pass_time :: TIMESTAMP
        END AS created_at,
    CASE WHEN update_time = '' THEN NULL
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值