gpt4 book ai didi

SQL Server - 使用 Join 仅显示第二个表中的条目

转载 作者:行者123 更新时间:2023-12-04 05:48:48 26 4
gpt4 key购买 nike

我正在使用 SQL Server

我拥有的数据是:

table1:

R_Time ID Q1
2012-02-26 14 8
2012-02-27 14 7
2012-02-27 15 8
2012-02-27 16 9
2012-02-27 11 10
2012-02-28 11 6
2012-02-28 14 10
2012-02-28 15 9


table2:

ID Supervisor
11 2
14 2
15 3
16 3

我想要到期的只是显示 table1 中的 R_Time 和 Q1 条目,其中 table2 主管为 3

我知道我将不得不以某种方式加入,但我不太确定如何加入。

谢谢。

最佳答案

说明
您可以使用内部联接来完成此操作。

T-SQL INNER JOIN operator can be used in any FROM clause to combine records from two tables.


sample
Select tbl1.R_Time, tbl1.Q1 from table1 tbl1
inner join table2 tbl2 on tbl2.Id = tbl1.Id
where tbl2.Supervisor = 3
更多信息
  • T-SQL - Inner Join
  • 关于SQL Server - 使用 Join 仅显示第二个表中的条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10340754/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com