考研 408 × 求职面试
知识点 · 数据库系统 · 进阶
每日一题 · 数据库系统
解析
面试小贴士 · 数据库系统
代码实现 · C
#include <stdio.h>
typedef struct { int A, B; } R;
typedef struct { int B, C; } S;
int main() {
R r[] = {{1,2},{3,2},{5,4}};
S s[] = {{2,7},{4,8},{2,9}};
// 等值连接:保留两表属性,包括重复的 B 列
puts("等值连接 R.B=S.B,保留两表属性:");
for (int i=0;i<3;i++)
for (int j=0;j<3;j++)
if (r[i].B == s[j].B)
printf("(%d,%d,%d,%d)\n", r[i].A,r[i].B,s[j].B,s[j].C);
// 自然连接:等值匹配后去掉重复的 B 列
puts("自然连接:等值匹配后去掉重复 B 列:");
for (int i=0;i<3;i++)
for (int j=0;j<3;j++)
if (r[i].B == s[j].B)
printf("(%d,%d,%d)\n", r[i].A,r[i].B,s[j].C);
return 0;
}