【发布时间】:2020-02-03 09:46:23
【问题描述】:
我的数据库中有这三个表,我想从三个表中选择共同的日期来计算每天的利润,每个月的利润,每年的利润
这是我的桌子:
Schema::create('expenses', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->float('amount');
$table->string('month');
$table->string('year');
$table->string('date');
});
Schema::create('service_orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('client_id')->unsigned();
$table->double('total_price', 8, 2)->nullable();
$table->string('month');
$table->string('year');
$table->date('date');
$table
->foreign('client_id')
->references('id')
->on('clients')
->onDelete('cascade');
});
Schema::create('orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('client_id')->unsigned();
$table->double('total_price', 8, 2)->nullable();
$table->string('month');
$table->string('year');
$table->date('date');
$table
->foreign('client_id')
->references('id')
->on('clients')
->onDelete('cascade');
});
【问题讨论】:
-
尝试使用
join查询 - laravel.com/docs/5.8/queries -
我会建议你,根据你想要的日期获取 3 种不同的数据。之后,通过php计算。这对你来说会更容易。
标签: eloquent laravel-6.2