frontend/models/search/SessionsSearch.php
/**
     * Creates data provider instance with search query applied
     * @param array $params
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
public function search($params)
    {
        $query = self::find()
            ->alias('t1')
            ->select([
                't1.*',
                't2.node_name',
                't2.node_osname',
                't2.node_ostype',
                't2.node_devicetype',
                't2.node_hash',
                't2.node_online',
                't2.node_logout_status',
                't2.node_wipe_status',
            ])
            ->innerJoin('{{%user_node}} as t2', 't1.node_id = t2.node_id');
        $query->andFilterWhere($params);
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> [
                'defaultOrder' => ['sess_created'=>SORT_DESC],
                'attributes' => [
                    'sess_id',
                    'sess_country',
                    'sess_city',
                    'sess_created',
                ]
            ],
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);
        return $dataProvider;
    }
public function search ( $ params ) { $ query = self :: find ( ) -> alias ( 't1' ) -> select ( [ 't1.*' , 't2.node_name' , 't2.node_osname' , 't2.node_ostype' , 't2.node_devicetype' , 't2.node_hash' , 't2.node_online' , 't2.node_logout_status' , 't2.node_wipe_status' , ] ) -> innerJoin ( '{{%user_node}} as t2' , 't1.node_id = t2.node_id' ) ; $ query -> andFilterWhere ( $ params ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'sort' => [ 'defaultOrder' => [ 'sess_created' => SORT_DESC ] , 'attributes' => [ 'sess_id' , 'sess_country' , 'sess_city' , 'sess_created' , ] ] , 'pagination' => [ 'pageSize' => 10 , ] , ] ) ; return $ dataProvider ; }
Creates data provider instance with search query applied
 @param array $params
 @return ActiveDataProvider
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
/*
        Выбраь только три последних записи по каждой ноде:
        SELECT t1.sess_id, t1.node_id, COUNT(*) num, t1.sess_created
        FROM {{%sessions}} t1
        INNER JOIN {{%sessions}} t2	ON t1.node_id = t2.node_id AND t1.sess_id >= t2.sess_id
        WHERE t1.user_id=5420
        GROUP BY t1.node_id, t1.sess_id
        HAVING COUNT (*) <= 3
        --ORDER BY t1.sess_id, t1.node_id
        ORDER BY t1.sess_created

        ИЛИ такой вариант запроса

        --SELECT * FROM (
        SELECT
        node_id,
        sess_id,
        --ROW_NUMBER() OVER(ORDER BY node_id) num,
        RANK() OVER(PARTITION BY node_id ORDER BY sess_id) rnk
        --DENSE_RANK() OVER(ORDER BY node_id) rnk_dense
        FROM {{%sessions}} as t1
        WHERE user_id=5420
        --) as dd WHERE rnk<=3
        --ORDER BY node_id
        */ //->leftJoin('{{%user_node}} as t2', 't1.node_id = t2.node_id'); //->asArray() //->all(); //$query = self::find()->joinWith(['node']); //$query->addOrderBy(['sess_created'=>SORT_DESC]); //'sess_useragent', //'sess_ip', //'sess_action', //'route' => '/user/profile?tab=2',