-2

我的问题是关于 SQL 查询

使用下表:

1. consultant(id,Name,Skill) 
2. CustomerCompany(Id,name Address, Phone, Email, WebAddr,Market)
3. project(id,StartDate,EndDate,ConsultantID,CustomerId,Days)
4. Invoice(id,Date,Customer,Amount,Status) 
什么是 SQL 语句

查找在柏林和伦敦为客户工作的顾问的姓名

我认为您必须加入表格,但我无法确定查询,有什么建议吗?

4

3 回答 3

1

就像是

SELECT C.Name
FROM Consultant C
--Join on projects the consultant worked on
JOIN Project P ON P.ConsultantID = C.ConsultantID
--Join on the customer companies those projects were for
JOIN CustomerCompany CC ON CC.ID = P.CustomerID
--Addresses might have various formats, use the LIKE operator
WHERE CC.Address LIKE '%London%' OR CC.Address LIKE '%Berlin%'

可能会成功。

于 2013-05-09T17:23:32.213 回答
0
select 
con.Name
from CustomerCompany CustComp
inner join project PRO on PRO.CustomerId=CustComp.Id
inner join consultant con on con.id=PRO.ConsultantID
where CustComp.Address LIKE '%London%' OR CustComp.Address LIKE '%Berlin%'

加入

于 2013-05-09T17:25:51.107 回答
0

从您的问题中可以确定的很少,但您可以执行以下操作:

 SELECT Name from consultant c
 join CustomerCompany cc on c.id = cc.id
 WHERE market in ('London', 'Berlin')

基本join是这样的

 Select columnname from FirstTable alias
 join secondtable alias on fieldFromFirstTable = FieldFromSecondTable
 WHERE criteria.
于 2013-05-09T17:26:21.970 回答