考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

Using the query " select * from 表 1 inner join 表 2 on 表1.员工 id = 表 2.员工id " to query the two tables below, how many rows should the result contain? 表1=table1 表2=table2 客户id=customerID 客户姓名=customerName 员工id=staffID 订单id=orderID 订单金额=orderAmount
A. 2
B. 3
C. 4
D. 5
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

When the relationship between two tables is many-to-many, i.e. the join field has duplicate values in both tables, inner join only returns records that satisfy the condition in both tables.

正确答案是 D: 5。

分析如下:

在 SQL 查询中,`INNER JOIN` 操作会返回两个表中满足连接条件的所有行。在这个查询中,连接条件是 `表1.员工id = 表2.员工id`。

我们来看看两个表中的数据:

表1 (table1):
```
员工id 客户id 客户姓名
1 101 张三
2 102 李四
3 103 王五
4 104 赵六
5 105 孙七
```

表2 (table2):
```
员工id 订单id 订单金额
1 201 500
2 202 600
3 203 700
4 204 800
5 205 900
```

在这两个表中,`员工id` 是连接条件。我们可以看到每个 `员工id` 在两个表中都有对应的记录:

```
表1.员工id = 表2.员工id
1 = 1
2 = 2
3 = 3
4 = 4
5 = 5
```

因此,所有的 `员工id` 都有匹配的记录。所以,最终的查询结果将包含 5 行数据。

所以,正确答案是 D: 5。