我有两个表格,出货量和条目。按当月的星期选择
我必须选择并插入另一个表中所选item_id = 113的条目和item_id = 204的出货量,我的select是当前月份和年份的条目和出货量的总和。
我有这两个查询,每个项目。
总和(cantidad_ent)=项目数 出生日期=日期
SELECT sum(cantidad_ent) Entradas_Tortilla, DATEPART(wk, fecha) Semana, DATEPART(m, fecha) Mes, DATEPART(yy, fecha)
FROM entradas
where id_articulo=113
and month(fecha)=month(getdate()) and year(fecha)=year(getdate())
GROUP BY DATEPART(wk, fecha), DATEPART(m, fecha), DATEPART(yy, fecha)
order by DATEPART(wk, fecha), datepart(m, fecha)
总和(cant_sale)=出货数量
SELECT sum(cant_Sale) Salidas_Costales, DATEPART(wk, fecha) Semana, DATEPART(m, fecha) Mes, DATEPART(yy, fecha)
FROM salidas
where id_articulo=204
and month(fecha)=month(getdate()) and year(fecha)=year(getdate())
GROUP BY DATEPART(wk, fecha), DATEPART(m, fecha), DATEPART(yy, fecha)
order by DATEPART(wk, fecha), datepart(m, fecha)
他们返回
Tortillas_entries/Week/Month/Year
4503 27 7 2013
3822 28 7 2013
FlourSack_shipments/Week/Month/Year
7 27 7 2013
6 27 7 2013
文发送面粉袋从仓库出来,他们被处理成玉米饼,然后我们做一个入口从做的玉米饼。该查询由,所以我知道有多少饼和面粉袋发送和一个星期,我也必须要注册多少饼总麻袋一周
(tortillas_entries /面粉袋)为作了Rendimiento(生产性能) 七分之四千五百○三6分之3822
总发送同时注册进入玉米饼和麻袋的,所以在同一天,我们有多少麻袋被送往了多少玉米饼作了来自那些麻袋。
结果即时寻找会是这样的:
Tortillas_entries/FlourSack_Shipment/Performance/Week/Month/Year
4503 7 643.28 27 7 2013
3822 6 637 28 7 2013
在此先感谢!
是'fecha'类型的日期时间还是日期? –
Smalldatetime @ mr.Reband –