Код: Выделить всё
News::find()
->alias("n")
->select()
->where(
new Expression("DAY(cdate) = :userDay "
// выборка по региону,
. "AND MONTH(cdate) = :userMonth "
. "AND id_region = :id_region "
. "AND status >= :stat AND n.id NOT IN"
//и чтобы id не совпадало с id из таблицы this_day
. " (SELECT id_news FROM this_day)",
//агрументы для бандинга
[":userDay" => $dateDay,
":userMonth" => $currentMoth,
":id_region" => REGION_ID,
":stat" => 1]))
->andWhere(new Expression("YEAR(cdate) "
. "<> :year", [":year" => ($yearsInThDay !== null) ? end($yearsInThDay) : $dateYear,
]))
->joinWith("rating nr")
->groupBy('YEAR(cdate)')
->limit(4 - $countThisDayNew)
->orderBy("nr.rate DESC, cdate_int DESC")
->all();
Код: Выделить всё
$result = Table::find()
->from([
'new_table' => Table::find()
->orderBy([
'date' => SORT_DESC
])
])
->groupBy('test_id')
->all()