2017-09-25 98 views
0

我试图执行一个mysql查询,显示星期一到星期天在这个星期内做出的产品数量(在这个例子中代码中只有Lunes和Martes )错误1241操作数应该包含1列子查询weekday

我设法用一个单一的ID执行查询,但是当我想显示每个人时,它给了我错误。

select formatopeso.tipo_formato, (select sum(cantidad) 
from previsionpedidos 
where id_formatopeso = 1 and WEEKDAY(fecha) = 0) as Lunes, 
(select sum(cantidad) fromprevisionpedidos where id_formatopeso = 1 and WEEKDAY(fecha) = 1) 
as Martes, 
from previsionpedidos inner join formatopeso on 
previsionpedidos.id_formatopeso = formatopeso.id_formatopeso 
where formatopeso.id_formatopeso= 1 and yearweek(fecha,1) = yearweek(now()) 
group by formatopeso.tipo_formato; 

我试试这个,但我有一个错误ERROR 1241(21000):操作数应包含1列(S)

select formatopeso.tipo_formato, 
(select sum(cantidad) from previsionpedidos inner join 
formatopeso on previsionpedidos.id_formatopeso = formatopeso.id_formatopeso 
where WEEKDAY(fecha) = 0) as lunes, 
(select sum(cantidad),fecha from previsionpedidos 
inner join formatopeso on previsionpedidos.id_formatopeso = 
formatopeso.id_formatopeso 
where WEEKDAY(fecha) = 1) as Martes from previsionpedidos 
inner join formatopeso on previsionpedidos.id_formatopeso = formatopeso.id_formatopeso 
where yearweek(fecha,1) = yearweek(now()) 
group by formatopeso.tipo_formato; 

感谢

我需要表现出类似的结果:

+--------------+-------+--------+ 
| tipo_formato | Lunes | Martes | 
+--------------+-------+--------+ 
| 12Ø 70gr  | 175 | 250 | 
| 20Ø 150gr | NULL| NULL | 
| 22Ø 180gr | NULL| 125 | 
| 25Ø 220gr | 200 | NULL | 
| 28Ø 220gr | 175 | 250 | 
+--------------+-------+--------+ 

回答

0

您在FROM之前有过多逗号。

SELECT formatopeso.tipo_formato, 
    (SELECT SUM(cantidad) 
    FROM previsionpedidos 
    WHERE id_formatopeso = 1 
     AND WEEKDAY(fecha) = 0 
    ) as Lunes, 
    (SELECT SUM(cantidad) 
    FROM previsionpedidos 
    WHERE id_formatopeso = 1 
     AND WEEKDAY(fecha) = 1 
    ) as Martes 
FROM previsionpedidos 
INNER JOIN formatopeso on previsionpedidos.id_formatopeso = formatopeso.id_formatopeso 
WHERE formatopeso.id_formatopeso=1 
    AND yearweek(fecha,1) = yearweek(now()) 
GROUP BY formatopeso.tipo_formato; 
+0

5000分之193 感谢您的帮助的朋友,已经解决了该代码是干净,整洁,但我的要求是要能够显示所有与他的ID的产品,我可以只显示一个 – Sylar

相关问题