随笔-10  评论-10  文章-0  trackbacks-0

    今天在深入学习了数据库方面的知识。感觉挺吃力。 今天发现很多理论的知识掌握很不牢固,真是很惭愧,今后还得继续在理论上下工夫。再说今天接触的知识吧,今天老总深入讲解了关于select查询方法的使用,发现这个东西实在是太灵活了!目前的自己拿着一个小项目也无法找到下手的方向,这应该就是极度缺乏经验的表现,今后还得多多练习才能有显著的提高。关于select,我先是很无语,确实是非常的灵活,就其中的连接一项,就呛得我要死,看来自己在这几天还得多多看相关的资料多多做练习才行。希望在研究数据库的同志们也加油,多看书,多看看好的代码,多去理解,这样自己才能有提高。 最后,把今天在老总带领下完成的关于电子书店数据库系统的代码放在这里,对于老手来说非常的简单,望所有新手共勉!

(该代码没有涉及insert into,其中数据可以根据实际情况添加)

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 客户名称, 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

posted on 2006-11-07 21:50 细雨游风 阅读(244) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: