SELECT * FROM tailings t WHERE t.price = (SELECT MIN(t2.price) FROM tailings t2 WHERE t2.code_medication = t.code_medication) GROUP BY t.code_medication;
$subQuery = (new Query())->select('MIN(t2.price')->from('tailings t2')->where(['t2.code_medication = t.code_medication'])->groupBy('t.code_medication');
$query = Product::find()->select('*')->from('tailings t')->where(['t.price' => $subQuery]);
SELECT `code_medication` FROM tailings t WHERE t.price = (SELECT MIN(t2.price) FROM tailings t2 WHERE t2.code_medication = t.code_medication) GROUP BY t.code_medication
public function actionIndex()
{
$view = Yii::$app->request->get('view');
$sort_value = (int) Yii::$app->request->get('sort_value');
$pharm = Yii::$app->session;
if (isset($pharm['pid'])) {
$pharm_id = $pharm['pid'];
$pharms = Pharmacy::findOne(['pharm_id' => $pharm_id]);
}
if (!empty($pharms)) {
$query = Product::find()->joinWith('tailing')->where(['tailings.pharm_id' => $pharm_id]);
}
if (!empty($sort_value)) {
if ($sort_value === 1) {
$query = Product::find()->joinWith('tailing')->orderBy(['tailings.price' => SORT_ASC]);
} elseif ($sort_value === 2) {
$query = Product::find()->joinWith('tailing')->orderBy(['tailings.price' => SORT_DESC]);
} elseif ($sort_value === 3) {
$query = Product::find()->joinWith('tailing')->orderBy(['name_medication' => SORT_ASC]);
} elseif ($sort_value === 4) {
$query = Product::find()->joinWith('tailing')->orderBy(['name_medication' => SORT_DESC]);
}
}
if (empty($pharms) && empty($sort_value)) {
$query = Product::find()->with('tailing');
}
$countQuery = clone $query;
$pages = new Pagination([
'totalCount' => $countQuery->count(),
'pageSize' => 20,
'forcePageParam' => false,
'pageSizeParam' => false,
]);
$medicines = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index', [
'medicines' => $medicines,
'pages' => $pages
]);
}
$head = <<< EOT
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
EOT;
$head = <<< EOT
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
EOT;
$head = <<< EOT
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
EOT;
$files = explode("\t", file_get_contents('upload/file/' . $model->csvFile->name));
foreach ($files as $file) {
$str = explode("|", $file, 1000);
if (is_numeric($str[0])) {
$args[] = [
'id' => $str[0],
'ware' => $str[1],
'name' => $str[2],
];
} else {
continue;
}
}