framework/db/ActiveRecord.php
public static function findBySql($sql, $params = [])
    {
        $query = static::find();
        $query->sql = $sql;

        return $query->params($params);
    }
public static function findBySql($sql, $params = [])
    {
        $query = static::find();
        $query->sql = $sql;

        return $query->params($params);
    }
Creates an [[ActiveQuery]] instance with a given SQL statement.

Note that because the SQL statement is already specified, calling additional
query modification methods (such as `where()`, `order()`) on the created [[ActiveQuery]]
instance will have no effect. However, calling `with()`, `asArray()` or `indexBy()` is
still fine.

Below is an example:

```php
$customers = Customer::findBySql('SELECT * FROM customer')->all();
```

@param string $sql the SQL statement to be executed
@param array $params parameters to be bound to the SQL statement during execution.
@return ActiveQuery the newly created [[ActiveQuery]] instance