当前位置: 技术问答>java相关
这样的select语句写得出吗?
来源: 互联网 发布时间:2015-08-06
本文导语: 通过下面6张表: CREATE TABLE Lims_YPFX_ItemRecord ( ItemName VARCHAR2(50) NOT NULL, Item_ID VARCHAR2(20) NOT NULL, ItemConclu CLOB NULL, Item...
通过下面6张表:
CREATE TABLE Lims_YPFX_ItemRecord (
ItemName VARCHAR2(50) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
ItemConclu CLOB NULL,
ItemBegDate VARCHAR2(10) NULL,
ItemEndDate VARCHAR2(10) NULL,
PRIMARY KEY (Item_ID)
);
CREATE TABLE Lims_YPFX_Sample (
Sample_ID VARCHAR2(20) NOT NULL,
SampleName VARCHAR2(20) NOT NULL,
SampleType VARCHAR2(20) NOT NULL,
PRIMARY KEY (Sample_ID)
);
CREATE TABLE Lims_YPFX_ItemSample (
Sample_ID VARCHAR2(20) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
PRIMARY KEY (Sample_ID, Item_ID),
FOREIGN KEY (Item_ID)
REFERENCES Lims_YPFX_ItemRecord,
FOREIGN KEY (Sample_ID)
REFERENCES Lims_YPFX_Sample
);
CREATE TABLE Lims_YPFX_Group (
AnalGro_ID VARCHAR2(12) NOT NULL,
AnalGroName VARCHAR2(30) NOT NULL,
AOtherExpress VARCHAR2(500) NULL,
PRIMARY KEY (AnalGro_ID)
);
CREATE TABLE Lims_YPFX_ItemGroup (
AnalGro_ID VARCHAR2(12) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
PRIMARY KEY (Item_ID, AnalGro_ID),
FOREIGN KEY (AnalGro_ID)
REFERENCES Lims_YPFX_Group,
FOREIGN KEY (Item_ID)
REFERENCES Lims_YPFX_ItemRecord
);
CREATE TABLE Lims_YPFX_Side (
AnalSideName VARCHAR2(20) NOT NULL,
AnalSide_ID VARCHAR2(20) NOT NULL,
AnalSideState VARCHAR2(6) NOT NULL,
SendPerson VARCHAR2(10) NOT NULL,
Sample_ID VARCHAR2(20) NOT NULL,
SendDate VARCHAR2(10) NOT NULL,
Instrument VARCHAR2(200) NULL,
AnalWay VARCHAR2(4) NULL,
PRIMARY KEY (AnalSide_ID),
FOREIGN KEY (Sample_ID, SendPerson, SendDate)
REFERENCES Lims_YPFX_Apply
);
用查询语句得到一个新的表:
表头为:Item_ID,ItemName,AnalGro_ID ,AnalGroName,Sample_ID ,SampleName,AnalSide_ID,AnalSideName,它们在表中的关系有一对多和对对多两种,可以写出来吗?
急!!!!
在线等!!!!!!!!!!
CREATE TABLE Lims_YPFX_ItemRecord (
ItemName VARCHAR2(50) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
ItemConclu CLOB NULL,
ItemBegDate VARCHAR2(10) NULL,
ItemEndDate VARCHAR2(10) NULL,
PRIMARY KEY (Item_ID)
);
CREATE TABLE Lims_YPFX_Sample (
Sample_ID VARCHAR2(20) NOT NULL,
SampleName VARCHAR2(20) NOT NULL,
SampleType VARCHAR2(20) NOT NULL,
PRIMARY KEY (Sample_ID)
);
CREATE TABLE Lims_YPFX_ItemSample (
Sample_ID VARCHAR2(20) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
PRIMARY KEY (Sample_ID, Item_ID),
FOREIGN KEY (Item_ID)
REFERENCES Lims_YPFX_ItemRecord,
FOREIGN KEY (Sample_ID)
REFERENCES Lims_YPFX_Sample
);
CREATE TABLE Lims_YPFX_Group (
AnalGro_ID VARCHAR2(12) NOT NULL,
AnalGroName VARCHAR2(30) NOT NULL,
AOtherExpress VARCHAR2(500) NULL,
PRIMARY KEY (AnalGro_ID)
);
CREATE TABLE Lims_YPFX_ItemGroup (
AnalGro_ID VARCHAR2(12) NOT NULL,
Item_ID VARCHAR2(20) NOT NULL,
PRIMARY KEY (Item_ID, AnalGro_ID),
FOREIGN KEY (AnalGro_ID)
REFERENCES Lims_YPFX_Group,
FOREIGN KEY (Item_ID)
REFERENCES Lims_YPFX_ItemRecord
);
CREATE TABLE Lims_YPFX_Side (
AnalSideName VARCHAR2(20) NOT NULL,
AnalSide_ID VARCHAR2(20) NOT NULL,
AnalSideState VARCHAR2(6) NOT NULL,
SendPerson VARCHAR2(10) NOT NULL,
Sample_ID VARCHAR2(20) NOT NULL,
SendDate VARCHAR2(10) NOT NULL,
Instrument VARCHAR2(200) NULL,
AnalWay VARCHAR2(4) NULL,
PRIMARY KEY (AnalSide_ID),
FOREIGN KEY (Sample_ID, SendPerson, SendDate)
REFERENCES Lims_YPFX_Apply
);
用查询语句得到一个新的表:
表头为:Item_ID,ItemName,AnalGro_ID ,AnalGroName,Sample_ID ,SampleName,AnalSide_ID,AnalSideName,它们在表中的关系有一对多和对对多两种,可以写出来吗?
急!!!!
在线等!!!!!!!!!!
|
select t1.Item_ID,t1.ItemName,t4.AnalGro_ID ,t4.AnalGroName,t2.Sample_ID ,t2.SampleName,t6.AnalSide_ID,t6.AnalSideName
from Lims_YPFX_ItemRecord t1,Lims_YPFX_Sample t2,Lims_YPFX_ItemSample t3,Lims_YPFX_Group t4,Lims_YPFX_ItemGroup t5,Lims_YPFX_Side t6
where t1.Item_ID=t3.Item_ID and
t2.Sample_ID=t3.Sample_ID and
t1.Item_ID=t5.Item_ID and
t4.AnalGro_ID=t5.AnalGro_ID and
t2.Sample_ID=t6.Sample_ID
以下好像不对:
FOREIGN KEY (Sample_ID, SendPerson, SendDate)
REFERENCES Lims_YPFX_Apply
我将其看成为:
FOREIGN KEY (Sample_ID)
REFERENCES Lims_YPFX_Sample
from Lims_YPFX_ItemRecord t1,Lims_YPFX_Sample t2,Lims_YPFX_ItemSample t3,Lims_YPFX_Group t4,Lims_YPFX_ItemGroup t5,Lims_YPFX_Side t6
where t1.Item_ID=t3.Item_ID and
t2.Sample_ID=t3.Sample_ID and
t1.Item_ID=t5.Item_ID and
t4.AnalGro_ID=t5.AnalGro_ID and
t2.Sample_ID=t6.Sample_ID
以下好像不对:
FOREIGN KEY (Sample_ID, SendPerson, SendDate)
REFERENCES Lims_YPFX_Apply
我将其看成为:
FOREIGN KEY (Sample_ID)
REFERENCES Lims_YPFX_Sample