PDA

View Full Version : [q]



invisible
18-10-2002, 08:47
Mình dang làm 1 bài tập về SQL, các bạn giúp mình giải bài này với, khó quá a`, mấy câu trước thì dễ mà sao 2 câu đây khó quá hic hic :((

cho 1 database như sau:

Department(DeptID, DeptName, Descrip, Instname, State, Postcode)
Academic(AcID, DeptID, GiveName, FamName, Initials, Title)
Paper(PaID, Title)
Author(PaID, AcID)
Field(FieldID, ID, Title)
Interest(FieldID, AcID, Descrip)

question:
1. Do any institutions have a department where no academics have written a paper? If so, return the name of the institution and the department number.

2. Are there any academics with the same family name that have provided the same description for their field of interest? If so, return their given name, family name and the description of their field of interest.
Cảm ơn các bạn trước. :x

9Star
18-10-2002, 18:56
Bạn chỉ rõ khoá với ý nghĩa của một số thuộc tính trong từng bảng được không. chứ như vậy làm dễ sai lắm ;)

invisible
18-10-2002, 19:10
sorry nha;

In this database, DeptID, AcID, PaID, and FieldID are the identifiers of departments,
academics, papers, and fields of interest respectively. Each Academic belongs to one Department and is the Author of some (or no) Papers. Each Paper has at least one Author. The table Field describes areas of research work; each Academic works in some (or no) Fields, and may provide a description Descrip of their work.

Is that enough?:x

quangtovan
18-10-2002, 19:22
select d.deptname, d.instname

from department d, academic a, author au

where a.acid <> au.paid

and a.deptid = d.deptid


bạn thử câu 1) này thử, nhưng hình như là không ổn lắm :D, mình tính dùng subquery nhưng mà không rành lắm, để từ từ :D

9Star
18-10-2002, 22:31
OK Let me try...

9Star
19-10-2002, 00:04
Không biết có đúng không nhưng bạn thử coi nha.
1.
if Exists(Select DeptId From Academic Where Title isnull)
Begin
Print "The institutions and department where no academics have written a paper are: "
Select InstName, DeptId
From Department
Where DeptId in ( Select DeptId
From Academic
Where Title isnull;
);
End
Else Print "there no..."
2. Câu này không chắc đã chạy ;)
Select GiveName, FamName,Descript
From Academic A,Interest
Where A.AcId in (Select I.AcId
From Interest I, Interest N
Where I.FieldId=N.FielId
And I.AcId<>N.AcId
)

invisible
19-10-2002, 15:40
thanks 9star very very much, however question number 2 does not work, could you keep going?

9Star
19-10-2002, 23:13
Ah câu 2 không chay có lẽ do viet sai "chinh tả" một chút

Bạn sửa lại ha.
Select GiveName, FamName,Descript
From Academic A,Interest
Where A.AcId in (Select I.AcId
From Interest I, Interest N
Where I.FieldId=N.FieldId
And I.AcId<>N.AcId
)

Bây giờ thì chắc chạy rồi, nhưng không biết có đúng không thôi ;)

invisible
22-10-2002, 20:12
hu hu....:((

sao không ai chịu giúp em hết vậy? câu 2) quá khó đi, thử dủ cách mà nó không chịu chạy, nó cứ báo lỗi "column ambiguously defined" không à, giúp em với...

9Star
23-10-2002, 09:44
Hi invisible,

Vậy là nó vẫn chưa chạy sao? mình thử thì có thấy chạy mà, có lẽ mình tạo tên bảng hơi khác với của bạn, bạn sửa một chút nữa ha.

Select Distinct GiveName, FamName,Descrip
From Academic A,Interest
Where A.AcId in (Select I.AcId
From Interest I, Interest N
Where I.FieldId=N.FieldId
And I.AcId<>N.AcId
)

Mình mới thử tạo 2 bảng này thôi thì chạy được. Nếu bạn tạo đủ luôn tất cả các bảng và ràng buộc rồi thì bạn vào thư mục cài SQL rồi vào thư mục DATA bạn chép 2 file tên CSDL của bạn.LOG và file tên CSDL.MDB sau đó nén lại gửi lên đây được không để mình Test lại cho, mình lười tạo CSDL quá...;)