自从我进入数据库世界以来已经很长一段时间了,因为我现在主要是一名前端开发人员。
我有一个sql db表,如下所示:
Table::findOne(['name' => 'Andrew', 'Age' => '25'])->delete();
我需要一个查询,使表格看起来像这样:
app\models\Table does not have a primary key. You should either define a primary key for the corresponding table or override the primaryKey() method.
感谢任何帮助
答案 0 :(得分:1)
select
State,
sum(case when Status=1 then 1 else 0 end) '1',
sum(case when Status=2 then 1 else 0 end) '2',
sum(case when Status=3 then 1 else 0 end) '3',
sum(case when Status>0 then 1 else 0 end) 'total'
from Your_Table
group by State