请问一下这个需求的sql语句应该如何写呢?

浏览:335 发布日期:2016/11/25 分类:求助交流
请问一下这个需求的sql语句应该如何写呢?

通过uid判断用户扔了多少垃圾SELECT a.id AS zhongleiId,a.name AS lajiname,c.id AS lajiInfoid,c.uid,c.weight,c.ctime FROM ims_delixin_userrecord AS c LEFT JOIN ims_delixin_class AS a  ON c.classid=a.id WHERE  c.uid=1 GROUP BY lajiname
如下如图

但是还需要和垃圾种类总表联系起来,把垃圾的所有种类都呈现出来,如果投放的就显示查出的数据,没有投放的就显示0,这个实在在难倒我了,想了半天了,还是不知道如何过滤,拜大神,谢谢
public function doMobileIndex() {
        $uid = 1;
        $result = pdo_fetchall("select a.id as zhongleiId,a.name as lajiname,c.id as lajiInfoid,c.uid,c.weight,c.ctime from ims_delixin_userrecord as c left join ims_delixin_class as a  on c.classid=a.id where  c.uid=".$uid."");
       
        $weight_sum = pdo_fetchall("select ROUND(SUM(weight),1) as weight_sum from ims_delixin_userrecord where ims_delixin_userrecord.uid=".$uid."");
       
        $rubbishId=pdo_fetchall("select id,name from ims_delixin_class");
        var_dump($result);
       // var_dump($result);
        
        
    include $this->template("index");
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>