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 |
+--------------+-------+--------+
5000分之193 感謝您的幫助的朋友,已經解決了該代碼是乾淨,整潔,但我的要求是要能夠顯示所有與他的ID的產品,我可以只顯示一個 – Sylar