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
一段不知所云的SQL
最新推荐文章于 2024-04-28 10:00:33 发布
本文深入探讨了SQL在数据库查询中的应用,分享了高级查询技巧和实际案例,帮助读者提升SQL操作效率和数据处理能力。
摘要由CSDN通过智能技术生成