我正在尝试查找一个给我行'x'的查询:1-2-3-4 ...... 不是3-4-5-6-7 ......
这是我的疑问:
SELECT f1.`week`
,count(f2.`week`) AS X
,SUM(f2.inn) AS inn
,SUM(f2.`out`) AS `out`
FROM ( SELECT `week`
,SUM(IF(`etat` = 1,1,0)) AS inn
,SUM(IF(`etat` = 2,1,0)) AS `out`
FROM fait_stock
WHERE `week` BETWEEN 40 AND 51
GROUP BY `week`) AS f1
JOIN ( SELECT `week`
,SUM(IF(`etat` = 1,1,0)) AS inn
,SUM(IF(`etat` = 2,1,0)) AS `out`
FROM fait_stock
WHERE `week` BETWEEN 1 AND 51
GROUP BY `week`) AS f2
ON f2.`week` <= f1.`week`
GROUP BY f1.`week`
这是结果: