建表语句及表中的数据
create table orders
(
orderID number(3) primary key,
orderDate date
);
create table orderItem
(
itemID number(3) primary key,
orderID number(3),
itemType varchar(20),
itemName varchar(20),
theNumber number(3),
theMoney number(3),
constraint FK_orderID foreign key (orderID) references orders(orderID)
);
insert into orders values(1,to_date('2008-01-12','yyyy-mm-dd'));
insert into orders values(2,to_date('2008-02-10','yyyy-mm-dd'));
insert into orders values(3,to_date('2008-02-15','yyyy-mm-dd'));
insert into orders values(4,to_date('2008-03-10','yyyy-mm-dd'));
insert into orders values(5,to_date('2008-09-10','yyyy-mm-dd'));
insert into orderItem values(1,1,'文具','笔',72,2);
insert into orderItem values(2,1,'文具','笔',10,1);
insert into orderItem values(3,1,'体育用品','篮球',1,56);
insert into orderItem values(4,2,'文具','笔',36,2);
insert into orderItem values(5,2,'文具','固体胶',20,3);
insert into orderItem values(6,2,'日常用品','透明胶',2,1);
insert into orderItem values(7,1,'体育用品','羽毛球',20,3);
insert into orderItem values(8,3,'文具','订书机',20,3);
insert into orderItem values(9,3,'文具','订书针',10,3);
insert into orderItem values(10,3,'文具','裁纸刀',5,5);
insert into orderItem values(11,4,'文具','笔',20,2);
insert into orderItem values(12,4,'文具','信纸',50,1);
insert into orderItem values(13,4,'日常用品','毛巾',4,5);
insert into orderItem values(14,4,'日常用品','透明胶',30,1);
insert into orderItem values(15,4,'体育用品','羽毛球',20,3);
根据某个时间段进行查询数据
select * from orders o inner join orderItem os on o.orderid=os.orderid where orderDate between to_date('2008-01-01','yyyy-mm-dd') and to_date('2008-02-20','yyyy-mm-dd');
查询结果为:
|