当前位置:首页 >> 求助mysql两张表统计查询 >>


用”SELECT a.*,COUNT(b.`category`) AS product_num FROM (`pl_category` a) LEFT JOIN `pl_product` b ON b.`category` = a.`id` Group By a.`id` ORDER BY a.`id`“ Group By不对,b表里是没有数据的,不能以b表中的category来Group By。

使用二个join on把三张表关联 然后写group by进行统计查询

select a.*,c.*,t.status,t.cou from a left join b on a.id=b.aid left join c on b.cid=c.id left join (select a.id,d.status,count(*) cou from a left join d ona.id=d.id group by a.id,d.status) t on a.id=t.id

mysql 不用union,不用子查询.如何把两张表数据合并.求助 select a.time,sum(regTime) regSum,sum(logTime) logSum from (select regTime time,1 regTime , 0 logSum from user union all select logTime time,0 regTime , 1 logSum from login) ...

一使用SELECT子句进行多表查询 SELECT 字段名 FROM 表1,表2 … WHERE 表1.字段 = 表2.字段 AND 其它查询条件 SELECT a.id,a.name,a.address,a.date,b.math,b.english,b.chinese FROM tb_demo065_tel AS b,tb_demo065 AS a WHERE a.id=b.id 注:在...



小王那个这么写: 1 select * from 表1 where id not in (select id from 表2) 后边表格那个: 1 select * from 表1 where 性别='女' and id not in (select id from 表2 where 日期='20171026')

$dd=mysql_num_rows($rs); $rs 是结果集 $DD就是返回行数

select count(表中任意属性名,如name) from [table_name]; 比如说我有一张state的表,它由姓名年龄构成 select count(name) from state; 希望能帮到你

网站首页 | 网站地图
All rights reserved Powered by www.nbcj.net
copyright ©right 2010-2021。