sql - 如何从 2 个不同的表中选择一个共同属性,其中一个共同属性的出现率最高?
问题描述
所以我有一个表“事故”,以及属性“pess_segura”,它是参与事故的受保人的数量。
我还有一个表“acid_pess”,其中有两个相关属性与此问题“事故”和“pessoa”,该表指的是卷入无法保证的事故的人(他们参与了事故但他们没有开车)。所以我想选择大多数人参与的事故。
这些是本练习的相关表格
create table person(
n_pess bigint not null,
nif integer not null,
cart_cond varchar(15),
pais_cart_cond varchar(30),
doc_id varchar(15) not null,
pais_doc_id varchar(30) not null,
nome varchar(80) not null,
primary key(n_pess),
unique(nif),
unique(cart_cond),
unique(doc_id)
);
create table ensurance(
apolice bigint not null,
ensured bigint not null,
veiculo bigint not null,
datai date not null,
dataf date not null,
cobertura numeric(10,2) not null,
primary key(apolice),
unique(ensured, veiculo),
foreign key (ensured) references person(n_pess),
foreign key (veiculo) references veiculo(n_veic)
);
create table accident(
n_acid bigint not null,
pess_segura bigint not null,
veic_seguro bigint not null,
data date not null,
local varchar(255) not null,
descr text not null,
primary key(n_acid),
unique(n_acid, veic_seguro),
foreign key (pess_segura,veic_seguro) references ensurance(ensured, veiculo)
);
create table acid_pess(
accident bigint not null,
person bigint not null,
veiculo bigint not null,
descr text not null,
primary key(accident, person),
foreign key (accident) references accident(n_acid),
foreign key (person) references person(n_pess),
foreign key (accident, veiculo) references accident(n_acid, veic_seguro)
);
我想选择参与人数最多的 n_acid(事故数量)。
解决方案
推荐阅读
- c# - Task.Run 仍然冻结 UI
- variables - 如何使用变量作为不同变量的数据类型?
- r - R 包 twitteR 中的推文函数之间无法解释的差异
- html - 正则表达式排除与负前瞻匹配的所有组
- laravel - 获取时无法更新函数内部的 vue 数据?
- regex - pgbadger 匹配 RDS 日志的正确模式是什么?
- python - 如何让创建语句尊重自定义 Django 字段中的“from_db_value”?
- google-cloud-platform - 使用 AutoML 对象检测接收到的 JSON 负载无效
- java - CountDownTimer 为每个循环增加时间
- .htaccess - htaccess 通过仅匹配 url 的第一部分来重写 url