直接sql语句查询到两条数据,程序执行只有一条数据 [ 2.0 版本 ]
$query = Order::find();
$query->select('order
.id,order
.code,order
.apply_no,
order
.create_time,order
.create_id,order
.update_time,order
.engineer,
order
.type,order
.store_id,order
.status,order
.name,order
.phone,
order
.appointment_time,order
.district,order
.address,order
.remark,
car_install
.vin,car_install
.license_plate,car_install
.car_owner_name,
product_package.name as package_name,driver.code as driver_code,driver.install_place');
$this->load($params);
$query->join('LEFT JOIN',Driver::tableName(),'driver
.order_id = order
.id AND driver
.deleted = 0 ');
if ($this->driverCode){
$query->andFilterWhere([Driver::tableName().'.code'=>$this->driverCode]);
}
$query->orderBy(Order::tableName().'.id desc');
$offset = $page*$pageSize;
$data = $query->limit($pageSize)->offset($offset)->asArray()->all();
打印sql为
SELECT
`order`.`id`, `order`.`code`,
`order`.`apply_no`, `order`.`create_time`,
`order`.`create_id`, `order`.`update_time`,
`order`.`engineer`, `order`.`type`,
`order`.`store_id`, `order`.`status`,
`order`.`name`, `order`.`phone`,
`order`.`appointment_time`, `order`.`district`,
`order`.`address`, `order`.`remark`,
`car_install`.`vin`, `car_install`.`license_plate`,
`car_install`.`car_owner_name`,
`product_package`.`name` AS `package_name`,
`driver`.`code` AS `driver_code`,
`driver`.`install_place`
FROM
`order`
LEFT JOIN car_install
ON order
.id
= car_install
.order_id
LEFT JOIN product_package
ON car_install
.product_id
= product_package
.id
LEFT JOIN driver
ON driver
.order_id = order
.id
AND driver
.deleted = 0
WHERE
(`order`.`code` LIKE '%YK2019122110257981%')
AND (order
.customer_id
= '152')
AND (order
.store_id
IN ('10479', '10524'))
AND (order
.deleted
= 0)
ORDER BY
`order`.`id` DESC
LIMIT 2000
把sql放到数据库执行查询到两条条数据,但是程序执行出来只有一条,想请教是哪里出了问题?
最佳答案
-
你用 (yii\db\Query())试试。
也许用find()查询主表外的字段都能忽略。共 1 条回复不求而得的往往求而不得 回复于 2019-12-28 14:54 回复问题已经解决了,https://www.yiichina.com/tutorial/1588,答案在这。
查询出主表id并起别名就好了,话说这个操作真的奇怪。。
其他 0 个回答
不求而得的往往求而不得 上海
最后登录:2022-03-08
在线时长:18小时17分
- 粉丝0
- 金钱135
- 威望40
- 积分715