我有两个观点,
View one: company_id, company_name,countA
View Two: company_id, Company_name, CountB
我想将这两个视图加入一个新视图,但结果集我需要如下:
company_id, company_name, countA,countB.
我做了研究,我尝试了加入和合并,但我无法弄明白。任何帮助将不胜感激。
谢谢
答案 0 :(得分:0)
您可以尝试这样:
select view1.company_id, view1.company_name, view1.countA,view2.countB
from view1 inner join view2 on view1.company_id = view2.company_id
答案 1 :(得分:0)
如果要包含来自两个视图的行,则应使用mysql中不可用的完全外连接。虽然有一些环形交叉路口:
SELECT view1.company_id, view1.company_name,countA,countB
FROM view1 LEFT JOIN view2 ON view1.company_id = view2.company_id
UNION
SELECT view2.company_id, view2.company_name,countA,countB
FROM view1 RIGHT JOIN view2 ON view1.company_id = view2.company_id
WHERE view1.company_id IS NULL