
正文
包含thinkphpunioncount的词条
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
thinkphp中怎么用group和count查询三篇文章各自的评论数
文章评论数,1.首先你有个文章表吧article_id假设这个是文章表的自增ID,2.你还得有个评论表吧,评论表里面肯定有个关联的文章ID吧假设这个字段是comment_article_id;那么你现在要做的是关联2个表 select count(1),b.article_title from 评论表 a left join 文章表 b on a.comment_article_id = b.article_id where a.article_id in (1,2,3) group by a.article_id;这样应该可以,没测试 其中1,2,3代表的是3篇文章的ID
相关问答
Q1: thinkphp union 使用问题 请教大神
这个是tp union的手册
然后从你的报错内容来看,是表找不到的问题
我想是不是你加一下
$ProductView = $Model-field('productid')
-table('mr_productspreadinfotj_20160522')
-union('SELECT `productid` FROM `mr_productspreadinfotj_20160523`');
这样会好。
Q2: THINKPHP里视图模型如何实现COUNT查询?
'cate'=array('id','name'),
'Category'=array('count(*)'='nums', '_on'='blog.cid=cate.id'),
Q3: thinkphp中union使用问题
union('SELECT createTime,title,readCount,id,belong FROM gq_preferential WHERE topic="top" and id='.$id)
or
union("SELECT createTime,title,readCount,id,belong FROM gq_preferential WHERE topic='top' and id='$id'")
Q4: thinkphp中怎么用group和count
$count=M("Table")-where($w)-count();//相当于下一行:
$count=M("Table")-field("count(*) as count)-find();
$count=$count['count'];
$list=M("Table")-group("age")-select();//按age分组查找
关于thinkphpunioncount和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






