mysql 查询问题
SELECT distinct c.imsi,ct.city_name,cxcg FROM cmcc_tbl c
left join city_tbl ct on c.imsi=ct.code_num
left join (select imsi,count(id) as cxcg from cmcc_tbl group by imsi) as cs on c.imsi=cs.imsi
union all
SELECT distinct c.imsi,ct.city_name,cxcg FROM cuni_tbl c
left join city_tbl ct on c.imsi=ct.code_num
left join (select imsi,count(id) as cxcg from cuni_tbl group by imsi) as cs on c.imsi=cs.imsi
这个查询 我想要 这二条记录汇总成一条,因为我要cxcg 的总数的
答案:这不是一条语句吗?要cxcg的总数,可以再在外面嵌套一个select,select sum(cxcg) from (上面的sql语句)
上一个:Navicat for MySQL学术论坛
下一个:安装好mysql之后,如何运行后缀为.sql文件?