我正在尝试使用pivot.main_contact = 1提取所有公司和联系人。
表格:
Company: id, name
Company_contacts: id, company_id, contact_id, main_contact
Contacts: id, name
Run Code Online (Sandbox Code Playgroud)
模型:
class Company extends Model
{
public function mainContact()
{
return $this->belongsToMany('App\Contact', 'company_contacts')
->wherePivot('main_contact', '=', 1);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器:
$query = Company::with('mainContact')->get();
Run Code Online (Sandbox Code Playgroud)
这将返回公司 + 公司的所有联系人,而不仅仅是 main_contact = 1 的联系人。
我刚刚开始使用 numpy..
得到下面的 np 表,想计算每个单元格占列总数的百分比。
data = np.array([[7,16,17], [12,11,3]])
headers = ["Grundskola", "Gymn", "Akademisk"]
# tabulate data
table = tabulate(data, headers, tablefmt="github")
# output
print(table)
| Grundskola | Gymn | Akademisk |
|--------------|--------|-------------|
| 7 | 16 | 17 |
| 12 | 11 | 3 |
Run Code Online (Sandbox Code Playgroud)
到:
| Grundskola | Gymn | Akademisk |
|--------------|--------|-------------|
| 39%| 59% | 85% |
| 61%| 41% | 15% |
Run Code Online (Sandbox Code Playgroud)
我知道 np.sum(data2, axis=0/1) 会给我总数,但我如何使用它来计算数组。
数组的大小可以不同...
您将如何找到多行的真实加权平均值:
通过实际加权,我的意思是像这个计算器:https : //www.rapidtables.com/calc/math/weighted-average-calculator.html(而不是通过将值与权重相乘)。
每个答案的权重设置answers在 child-table 中,每个问题的值都在 child-table 中answer_items。我们想要每个question(a,b,c,d)的加权平均值。我们提前知道要查找哪些问题。
查询将包含 2 到 500k 个答案(所以最好是一个快速的解决方案:))
CREATE TABLE `answers` (
`id` int(10) NOT NULL,
`weight` varchar(255) NOT NULL
);
INSERT INTO `answers` (`id`, `weight`) VALUES
(1, '0.7'),
(2, '1'),
(3, '0.7'),
(4, '0.9');
CREATE TABLE `answer_items` (
`id` int(11) NOT NULL,
`answer_id` int(11) NOT NULL,
`question` varchar(5) NOT NULL,
`value` int(11) NOT NULL
);
INSERT INTO `answer_items` (`id`, `answer_id`, `question`, …Run Code Online (Sandbox Code Playgroud) 我正在努力解决项目的 nuxt 文件夹/路由结构:
我想要实现: 所有这些都应该显示pages/data/index.vue:
www.example.com/data
www.example.com/data/region
www.example.com/data/region/industry
Run Code Online (Sandbox Code Playgroud)
然后通过 访问参数区域或行业$route-class。
如果我添加_region文件夹和_industy.vue它会显示这些文件,并且我想显示和使用index.vue.