??? 今天在深入學(xué)習(xí)了數(shù)據(jù)庫(kù)方面的知識(shí)。感覺(jué)挺吃力。 今天發(fā)現(xiàn)很多理論的知識(shí)掌握很不牢固,真是很慚愧,今后還得繼續(xù)在理論上下工夫。再說(shuō)今天接觸的知識(shí)吧,今天老總深入講解了關(guān)于select查詢方法的使用,發(fā)現(xiàn)這個(gè)東西實(shí)在是太靈活了!目前的自己拿著一個(gè)小項(xiàng)目也無(wú)法找到下手的方向,這應(yīng)該就是極度缺乏經(jīng)驗(yàn)的表現(xiàn),今后還得多多練習(xí)才能有顯著的提高。關(guān)于select,我先是很無(wú)語(yǔ),確實(shí)是非常的靈活,就其中的連接一項(xiàng),就嗆得我要死,看來(lái)自己在這幾天還得多多看相關(guān)的資料多多做練習(xí)才行。希望在研究數(shù)據(jù)庫(kù)的同志們也加油,多看書(shū),多看看好的代碼,多去理解,這樣自己才能有提高。 最后,把今天在老總帶領(lǐng)下完成的關(guān)于電子書(shū)店數(shù)據(jù)庫(kù)系統(tǒng)的代碼放在這里,對(duì)于老手來(lái)說(shuō)非常的簡(jiǎn)單,望所有新手共勉!
(該代碼沒(méi)有涉及insert into,其中數(shù)據(jù)可以根據(jù)實(shí)際情況添加)
create table customers
(customerID int primary key not null,
customername varchar(20) not null);?
create table books
(bookid int primary key not null,
booktitle varchar(50) not null,
unitprice int not null
);?
create table orders
(orderid int primary key not null,
orderdate date default sysdate not null,
customerid int not null,
constraint fk_c foreign key (customerid) references customers(customerid)
);?
create table orderitems
(OrderItemID int primary key not null,
orderid int not null,
bookid int not null,
quantity int default '1' not null,
constraint fk_b foreign key (bookid) references books(bookid), constraint fk_o? foreign key (orderid) references orders(orderid));?
select c.customername as 客戶名稱(chēng), sum(b.unitprice * oi.quantity)
from customers c
left join orders o on c.customerid = o.customerid
left join orderitems oi on o.orderid = oi.orderid
left join books b on oi.bookid = b.bookid
where to_char(o.orderdate,'yyyy') = to_char(sysdate,'yyyy')
group by c.customername