亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

tp5語法 group by 和count(*)連用

tp5語法 group by 和count(*)連用

PHP
九州編程 2019-03-18 15:25:18
like 表字段idtypeid 文章iduserid 用戶idstatus 贊狀態 1:已點贊 0:未點贊 想知道某文章id為1,2,3,4的總贊數,不知道怎么用tp5寫原生sql="select typeid,count(*) from like where typeid in (1,2,3,4) and user_id = 14 and status =1 group by typeid"; tp5只知道這么寫$ids= '1,2,3,4';LikeModel::where('typeid','in',$ids)->where(['user_id'=>14,'status'=>1)->group('typeid')->select(); 沒有用上count(*) 我想實現 typeid count(*)1 12 23 24 1
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

其實這個要用到filed這個方法,例子

LikeModel::where('typedid','in',$ids)
    ->where(['user_id'=>14,'status'=>1])
    ->filed('typeid,COUNT(*) as total')
    ->group('typeid')
    ->select();

沒有太過于去查看,大概就這個意思

查看完整回答
反對 回復 2019-03-18
  • 1 回答
  • 0 關注
  • 4424 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號