如何从具有相同ID的不同行的两个表创建视图 [英] How do I create view from two tables having different rows with same ID
问题描述
如何从具有相同ID的不同行的两个表创建视图
编辑(来自解决方案2):
表是
诊断(id,费用,ddate,doct)
分析(id,afees, ano,aname,adate)
编辑(来自解决方案3):
诊断值为(1,100,21-6,ali)
分析值为(1,50,23,cbc,21-6)
秒行分析值为(1,70,33,尿素,21-6)
视图为
创建视图v_accont as(selecy d.id,d.fees, d.ddate,d.doct,a.aname,a.afees from diagnosis d inner join analysis a on d.id = a.id)
我得到了
Id费用ddate doct aname afees
1 100 21-6 ali cbc 50
1 100 21-6 ali尿素70
我希望这个是cleat
How to creat view from two table having different rows with same ID
Edit (from "Solution 2"):
the tables are
Diagnosis(id,fees,ddate,doct)
Analysis(id,afees,ano,aname,adate)
Edit (from "Solution 3"):
diagnosis values are(1,100,21-6,ali)
Analysis values are(1,50,23,cbc,21-6)
Second row analysis values are(1,70,33,urea,21-6)
The view is
Create view v_accont as(selecy d.id,d.fees,d.ddate,d.doct,a.aname,a.afees from diagnosis d inner join analysis a on d.id=a.id)
I'm getting
Id fees ddate doct aname afees
1 100 21-6 ali cbc 50
1 100 21-6 ali urea 70
I hope this is cleat
推荐答案
使用SQL join和create view
use SQL join and create view
CREATE VIEW view_Order AS
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
肯定您将获得两行,因为两行分析表的id列具有相同的值。要使它工作,你必须将第二行的值更改为( 2 ,70,33,尿素,21-6)
for sure you will be given two rows because 'id' column for the two rows of analysis table have the same value. To make it work you have to change the value of second row to (2,70,33,urea,21-6)
这篇关于如何从具有相同ID的不同行的两个表创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!