SELECT ywy,yhrq,pmonth AS '月份',IFNULL(LEFT((stotal/ptotal)*100,5),0)AS '达成率'
FROM
(SELECT ywy,yhrq,MONTH(yhrq) AS pmonth,CONCAT(yhbh,pk_corp) AS pid,SUM(sl) AS ptotal
FROM demandplan GROUP BY ywy,pmonth,pid)p LEFT JOIN
(SELECT MONTH(jzrq) AS smonth,CONCAT(DYDD,pk_corp) AS sid,SUM(jf_sl) AS stotal
FROM `cr_sasalesaccount` WHERE DYDD<>'' GROUP BY smonth,sid)s
ON pid=sid WHERE ywy = :M_ywy
AND LEFT(yhrq,7) BETWEEN :M_sdate AND :M_edate
GROUP BY ywy,pmonth
create table demandplan
SELECT
ywy,
yhrq,
yhbh,
pk_corp,
sl,
spdm,
spmc,
scgg,
bzgg
FROM
cr_demandplan
WHERE RecDR = 0)bb
INNER JOIN
(SELECT
yhbh,
pk_corp
FROM
cr_demandplan
WHERE RecAs3 = '通过'
GROUP BY CONCAT(yhbh,pk_corp))aa
ON CONCAT(bb.yhbh, bb.pk_corp) = CONCAT(aa.yhbh, aa.pk_corp
嵌套成一个语句
------解决思路----------------------
还是create table demandplan这句SQL,“)bb”对应的(在哪里?怎么看起来这个SQL语句复制的不全啊,首先要保证这个SQL语句能正确执行,再放到第一个SQL语句中。