在这种情况下 - 表'区'有两列 - id,district。 表'派对'有列 - parties_partyname,parties_district
parties.parties_partyname = districts.district
另一个表'bill'有列partyname,billamount。
bills.partyname = parties.parties_partyname
现在我想要的是看下面的每个区的billamount -
District Sale
A 10000
B 20000
C 10000
D 20000
我的搜索查询是 -
$query = Districts::find();
$subquery = Bills::find()->select('parties_district,bills_partyname, billdate, sum(billamount) as sale')->groupBy(['parties_district']);
$subquery->joinWith(['parties']);
$query->leftJoin(['T' => $subquery], 'T.parties_district = districts.district');
我在销售栏中收到“(未设置)”。请告诉我需要做哪些更改。 另外,我试图在partySearch模型中打破这样的部分 -
$query = Parties::find();
$subquery = Bills::find()->select('bills_partyname, billdate, sum(billamount) as sale')->groupBy(['bills_partyname']);
$query->leftJoin(['T' => $subquery], 'T.bills_partyname = parties_partyname');
我仍然没有设置为销售栏
答案 0 :(得分:0)
我通过 - ' findbysql'找到了这个问题的解决方案。 Getting (not set) when joining a column which has a sum function in yii2 - 此链接对此问题很有帮助。