mysql查询语句:
SELECT
1 AS flag
,
s
.suppliers_id
, s
.company_name
, s
.city
FROM supplier
s
可查询到数据,无错误
yii2查询写法:
Supplier::find()
->alias('s')
->select('1 as flag,s.suppliers_id,s.company_name,s.city')->all();
报错: "msg": "SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list'\nThe SQL being executed was: SELECT 1
AS flag
, s
.suppliers_id
, s
.company_name
, s
.city
FROM supplier
s
",
初步判断为,使用yii select()方法查询的时候,yii语法把1当做一个表的字段加了单引号查询,所以保错Column not found。未找到解决方法,望大神指教
不懂php,这是php吧。但是呢,既然写死1了,加不加这列都没啥区别,可以不查flag列,等数据查出来以后,如果有必要,再遍历数据,把flag都设为1
在select()查询中,给1加括号: (1) as flag。完美解决