请教高手们指点下小弟:
现有张表d_month_salary结构和数据如下:
当要查询'网销','店铺'月份的环比和同比,以下语句怎么修改才能互不干扰
SELECT curmonth month, ((curmonth_sum - lastyear_sum) / lastyear_sum * 100) identical,((curmonth_sum - lastmonth_sum) / lastmonth_sum * 100) annulus
FROM (SELECT t.salarymonth curmonth,
SUM (t.salary) curmonth_sum,
(SELECT SUM (t1.salary) FROM d_month_salary t1 WHERE t1.salarymonth =((SUBSTR (t.salarymonth, 1, 4) - 1)|| SUBSTR (t.salarymonth, -2))) lastyear_sum,
(SELECT SUM (t1.salary) FROM d_month_salary t1 WHERE t1.salarymonth =TO_CHAR(ADD_MONTHS (TO_DATE (t.salarymonth, 'yyyymm'),-1),'yyyymm')) lastmonth_sum FROM d_month_salary t
WHERE indexname = ? //?='网销'或'店铺'
GROUP BY t.salarymonth
ORDER BY t.salarymonth)
|
|