我是在一家培训中心学习JAVA的,由于做JAVA开发必需要和数据库打交道,所以培训课程安排中有这方面的安排.我们先学的是SQL2000,后期学了ORACLE.
关于SQL的一些资料我放在了我的资源里面(博客里好像不给上传东西),有需要的就麻烦自己去找啦,呵可.
这里只将我学习期间做的一些题发上来让大家看一下,有什么错误还请大家多多指教.
全都是SQL自带的数据库,先是PUBS数据库的.
1.在pubs库中的publishers表中查找所有出版商业书籍的出版商的名称,用EXIST关键字完成
2.在pubs库中的publishers表中查找所有出版商业书籍的出版商的名称,用IN关键字完成
3.查找至少曾参与编写一本热门计算机(popular_comp类型)书的作者姓名
4.查找销售数量低于该书同类型平均销售数量(销售数量ytd_sales)的书的信息。
5.找到与 Livia Karsen 住在同一城市的作者
1.(where子句中要有两个条件)
select pub_name from publishers as p
where exists
(select pub_id from titles as t
where p.pub_id=t.pub_id
and type='business')
2.
select pub_name,pub_id from publishers
where pub_id in
(select pub_id from titles where type='business')
3.
select au_lname,au_fname from authors
where au_id in
(
select au_id from titleauthor where au_id in
(
select au_id from titles where titleauthor.title_id=titles.title_id
and type='popular_comp'
)
)
(另一种方法)
select au_id,au_lname,au_fname from authors
where au_id in
(select au_id from titleauthor
where title_id in
(select title_id from titles
where type = 'popular_comp'))
4. ★★★★★
select *
from titles as a
where ytd_sales <
(
select avg(ytd_sales)
from titles as b
where a.type = b.type
)
5.
select *from authors
where city in --in可以换成'='
(select city from authors
where au_fname='livia' and au_lname='karsen' )