1

我用谷歌搜索并搜索了这个地方,但找不到我能找到的答案,因为其他人的不同。

USE TestDatabase
Select Firstname,Lastname,Salary From Employee as E 
Join JobTitle as J
on E.JobTitleID = J.JobTitleID

WHERE Salary 
BETWEEN $25000.00 AND $50000.00

这可行,但我试图显示 JobTitle Table 中的两列,我不知道要搜索什么词或谷歌,也找不到简单的答案。任何人都可以帮助一些人,但我很困惑。我在学校使用服务器 2008 t-sql

4

5 回答 5

3

您可以使用表格的别名JobTitleJ选择您想要选择的任何额外列

Select Firstname, Lastname, Salary, 
   j.Field1, j.Field2 ... -- and other fields you want to select here
From Employee as E 
Join JobTitle as J
on E.JobTitleID = J.JobTitleID

WHERE Salary 
BETWEEN $25000.00 AND $50000.00
于 2012-09-06T13:46:03.013 回答
1

使用别名将谁是您正在使用的表设置到该字段。

Select
    E.Firstname,E.Lastname,E.Salary,
    j.JobTitle, j.Otherfieldyouwanttoselect
From Employee as E Join JobTitle as J on E.JobTitleID = J.JobTitleID
WHERE
    Salary BETWEEN $25000.00 AND $50000.00
于 2012-09-06T13:52:48.553 回答
0

你的意思是这样吗?

USE TestDatabase
Select Firstname,Lastname,Salary,J.YourcolumnfromJobTitle  From Employee as E 
Join JobTitle as J
on E.JobTitleID = J.JobTitleID

WHERE Salary 
BETWEEN $25000.00 AND $50000.00
于 2012-09-06T13:49:03.120 回答
0
Select E.Firstname, E.Lastname, E.Salary, J.Column1, J.Column2
    From Employee as E 
        Join JobTitle as J
            on E.JobTitleID = J.JobTitleID
    WHERE E.Salary BETWEEN $25000.00 AND $50000.00
于 2012-09-06T13:48:21.907 回答
0

您应该为这两个表使用别名,如下所示:

USE TestDatabase
Select E.Firstname,E.Lastname,E.Salary,J.Column1,j.Column2 From Employee as E 
Join JobTitle as J
on E.JobTitleID = J.JobTitleID

WHERE E.Salary 
BETWEEN $25000.00 AND $50000.00
于 2012-09-06T13:52:24.917 回答