将表合并到一个表中以避免重复值 [英] merge to table into one table avoiding duplicated values
本文介绍了将表合并到一个表中以避免重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表1
table 1
ID Name Address Basic_Salary Basic_Allowance
1 Moses MTM 1000 500
2 GEO NGL 3000 1500
另一张桌子
表2
Another table
table 2
ID Name Address Salary Allowance Month
1 Moses MTM 800 220 Nov
我需要结果
I Need the result
ID Name Address Salary Allowance Month Status
1 Moses MTM 800 220 Nov Paid
2 GEO NGL 3000 1500 Nov Not Paid
任何人都可以帮我解决问题
Can Any one help me how to solve it
推荐答案
您的问题不明确。但我假设您的第一张桌子是薪水表,第二张表已经付清。
根据您问题的模糊性,我想这是你想要什么:
Your question is not clear. But I am assuming that your first table is the Salary table and the second one which has been paid out.
Based on the vagueness of your question, I guess this is what you want:
SELECT
Salary.ID,
Salary.Name,
Salary.Address,
CASE WHEN Paid_Salary.Salary IS NULL THEN Salary.Basic_Salary ELSE Paid_Salary.Salary END AS Salary,
CASE WHEN Paid_Salary.Allowance IS NULL THEN Salary.Basic_Allowance ELSE Paid_Salary.Allowance END AS Allowance,
Paid_Salary.Month,
CASE WHEN Paid_Salary.Salary IS NULL THEN 'Not Paid' ELSE 'Paid' END AS Status
FROM
Salary LEFT JOIN Paid_Salary ON
Salary.Name = Paid_Salary.Name
这篇关于将表合并到一个表中以避免重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文