我有这样一个问题:
use yii\db\Expression;
public function search($params)
{
$query = (new \yii\db\Query())
->select([
"ir.id",
"ir.no_surat",
"tc.level",
"nominal" => 'tc.cleaning',
new Expression("clean as tagihan"),
"tc.ditagihkan_bulan"
])
->from('ydepotras_estimator.repair_estimate as re')
->leftJoin(['ydepotras_estimator.inspection_report as ir'],
"ir.id = re.inspection_id")
->innerJoin(['ydepotras_finance.tagihan_cleaning as tc'],
" re.id = tc.repair_estimate_id");
}
new Expression("clean as tagihan"),
检测到Yii2
clean
作为列。但我需要塔吉汉列上的clean as值
+----+-------------+
| id | tagihan |
+----+-------------+
| 1 | clean |
| 2 | clean |
+----+-------------+
使现代化
$cleanigQuery = (new \yii\db\Query())
->select([
"ir.id",
"ir.no_surat",
"tc.level",
"nominal" => 'tc.cleaning',
new Expression("clean as tagihan"),
"tc.ditagihkan_bulan"
])
->from('ydepotras_estimator.repair_estimate as re')
->leftJoin(['ydepotras_estimator.inspection_report as ir'],
"ir.id = re.inspection_id")
->innerJoin(['ydepotras_finance.tagihan_cleaning as tc'],
" re.id = tc.repair_estimate_id");
$oneBarQuery = (new \yii\db\Query())
->select([
"ir.id",
"ir.no_surat",
"tob.level",
"nominal" => 'tob.one_bar',
new Expression("one_bar as tagihan"),
"tob.ditagihkan_bulan"
])
->from('ydepotras_estimator.repair_estimate as re')
->leftJoin(['ydepotras_estimator.inspection_report as ir'],
"ir.id = re.inspection_id")
->innerJoin(['ydepotras_finance.tagihan_one_bar as tob'],
" re.id = tob.repair_estimate_id");
所以,我可以这样做:
$cleanigQuery->union($oneBarQuery, true);
$query = (new \yii\db\Query())
->select('*')
->from(['u' => $cleanigQuery])
->orderBy('no_surat');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);