22,209
社区成员
发帖
与我相关
我的任务
分享
--当日订单生产量
select C.ListID,C.PL,sum(C.ProNum) as Everyday_ProNum
from C
inner join
(
select A.ListID,max(A.sequence) as sequence
from A group by A.ListID
) SelSectionNo on (SelSectionNo.ListID=C.ListID and SelSectionNo.sequence=C.sequence)
where C.ProDate='2011-10-24'
group by C.ListID,C.LineCode
---这个真的已经比较简单了
select
*
from
a left join b
on
a.listID=b.listID
left join c on
a.listID=c.listID
and
b.prodate='2011-10-24'
and
C.ProDate='2011-10-24'
--总的生产量
select C.ListID,C.PL,sum(C.proNum) as Sum_ProNum
from C
inner join
(
select A.ListID,max(A.sequence) as sequence
from A group by A.ListID
) SelSectionNo on (SelSectionNo.ListID=C.ListID and C.sequence=SelSectionNo.sequence)
WHERE
EXISTS (SELECT 1 FROM B WHERE prodate='2011-10-24' AND ListID=c.ListID)
or
EXISTS(SELECT 1 FROM C AS d WHERE d.ListID=c.ListID AND d.prodate='2011-10-24')
1.
select
*
from
a join b
on
a.listID=b.listID
and
a.listID=c.listID
and
b.prodate='2011-10-24'
and
C.ProDate='2011-10-24'
作组别
select distinct ListID,PL,Everyday_PlanNum
from
(
select B.ListID,B.PL,B.planNum as Everyday_PlanNum
from B
where B.prodate='2011-10-24'
union all
select C.ListID,C.PL,0 as Everyday_PlanNum
from c
left join
(
select B.listID,B.PL from B
where B.proDate='2011-10-24'
) planNum on (planNum.ListID=C.ListID and planNum.PL=C.PL)
where C.prodate='2011-10-24'
and planNum.PL is null
SELECT
DISTINCT C.ListID,C.PL,ISNULL(B.planNum,0) AS Everyday_PlanNum
FROM C
LEFT JOIN B ON b.ListID=c.ListID AND b.PL=c.PL and B.proDate='2011-10-24'
SELECT
DISTINCT B.ListID,B.PL,ISNULL(B.planNum,0) AS Everyday_PlanNum
FROM C
LEFT JOIN B ON b.ListID=c.ListID AND b.PL=c.PL and B.proDate='2011-10-24'