Thinkphp 原生SQL到TP转化

select a.username ,c.nickname,b.ft,d.gz,e.fs from cjcp_user as a 

LEFT JOIN(select uid,count(1) as ft  from cjcp_forum_post GROUP BY uid) as b on a.uid = b.uid

LEFT JOIN(select uid,nickname from cjcp_user_info ) as c  on  a.uid =c.uid 

LEFT JOIN(select uid,count(uid) as gz from cjcp_user_follow GROUP BY uid) as d on a.uid= d.uid

LEFT JOIN(select followuid,count(followuid) as fs from cjcp_user_follow GROUP BY followuid) as e on a.uid= e.followuid

ORDER BY ft desc





$count = $userTab->alias("a")

            ->join("LEFT JOIN "."(select uid,count(1) as ft  from ".C('DB_PREFIX')."forum_post GROUP BY uid) as b on a.uid = b.uid")

            ->join("LEFT JOIN "."(select uid,nickname from ".C('DB_PREFIX')."user_info)  as c  on  a.uid =c.uid ")

            ->join("LEFT JOIN "."(select uid,count(uid) as gz from ".C('DB_PREFIX')."user_follow GROUP BY uid )as d on a.uid= d.uid")

            ->join("LEFT JOIN "."(select followuid,count(followuid) as fs from ".C('DB_PREFIX')."user_follow GROUP BY followuid) as e on a.uid= e.followuid")

            ->ORDER('ft desc')

            ->field("a.username ,c.nickname,b.ft,d.gz,e.fs")


            ->count();


上一篇: css样式大全(整理版) 下一篇: SQL基本使用