FROM
(select B.FMATERIALID, A1.FPRDORGID,B.Fname as 物料名称 , B.FSPECIFICATION as 规格,C.FACTUALQTY as 材积,
C.FPRICE,C.FACTUALQTY*C.FPRICE AS FCOUNT,A1.FDATE
from T_SP_PICKMTRLDATA c
INNER JOIN T_BD_MATERIAL_L B on C.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_PICKMTRL A1 ON C.FID = A1.FID
WHERE B.FNAME LIKE '%方%'
GROUP BY A1.FDATE,B.FSPECIFICATION ,C.FACTUALQTY ,B.FNAME ,C.FPRODUCEDATE,
B.FMATERIALID,C.FPRICE ,A1.FPRDORGID
HAVING A1.FDATE = '2016-10-01 00:00:00.000')M
INNER JOIN
(select B.FMATERIALID ,
B.FSPECIFICATION as 规格,
SUM(A.FREALQTY) as 材积,
A1.FPRDORGID ,
A1.FDATE
FROM T_SP_INSTOCKENTRY A
INNER JOIN T_BD_MATERIAL_L B on A.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_INSTOCK A1 ON A1.FID = A.FID
WHERE B.FNAME like '湿刨切表板'
GROUP BY B.FMATERIALID,B.FSPECIFICATION,A1.FPRDORGID,A1.FDATE
HAVING A1.FDATE = '2016-10-01 00:00:00.000')N ON M.FPRDORGID = N.FPRDORGID
像要的结果
出来的结果
3 个解决方案
#1
改成下面试试,两个结果集的组中,在FPRDORGID的基础上增加一个序号,以避免重复链接N返回的记录
SELECT * FROM (
SELECT ROW_NUMBER()OVER( PARTITION BY FPRDORGID ORDER BY A1.FDATE,B.FSPECIFICATION ,C.FACTUALQTY ,B.FNAME ,C.FPRODUCEDATE, B.FMATERIALID,C.FPRICE ,A1.FPRDORGID) AS rn
, B.FMATERIALID, A1.FPRDORGID,B.Fname as 物料名称 , B.FSPECIFICATION as 规格,C.FACTUALQTY as 材积,
C.FPRICE,C.FACTUALQTY*C.FPRICE AS FCOUNT,A1.FDATE
from T_SP_PICKMTRLDATA c
INNER JOIN T_BD_MATERIAL_L B on C.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_PICKMTRL A1 ON C.FID = A1.FID
WHERE B.FNAME LIKE '%方%'
GROUP BY A1.FDATE,B.FSPECIFICATION ,C.FACTUALQTY ,B.FNAME ,C.FPRODUCEDATE, B.FMATERIALID,C.FPRICE ,A1.FPRDORGID
HAVING A1.FDATE = '2016-10-01 00:00:00.000'
)M INNER JOIN (
SELECT ROW_NUMBER()OVER( PARTITION BY FPRDORGID ORDER BY B.FMATERIALID,B.FSPECIFICATION,A1.FPRDORGID,A1.FDATE) AS rn
,B.FMATERIALID , B.FSPECIFICATION as 规格, SUM(A.FREALQTY) as 材积,A1.FPRDORGID ,A1.FDATE
FROM T_SP_INSTOCKENTRY A
INNER JOIN T_BD_MATERIAL_L B on A.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_INSTOCK A1 ON A1.FID = A.FID
WHERE B.FNAME like '湿刨切表板'
GROUP BY B.FMATERIALID,B.FSPECIFICATION,A1.FPRDORGID,A1.FDATE
HAVING A1.FDATE = '2016-10-01 00:00:00.000'
)N ON M.FPRDORGID = N.FPRDORGID AND m.rn=n.rn
#2
您好,谢谢您恢复我的问题,但是这样出来的结果 就是第一行了
#3
我看的想要的不就是右表满足条件的记录不重复输出吗?
)M INNER JOIN (
这里要改成LEFT JOIN 我上面疏忽了
#1
改成下面试试,两个结果集的组中,在FPRDORGID的基础上增加一个序号,以避免重复链接N返回的记录
SELECT * FROM (
SELECT ROW_NUMBER()OVER( PARTITION BY FPRDORGID ORDER BY A1.FDATE,B.FSPECIFICATION ,C.FACTUALQTY ,B.FNAME ,C.FPRODUCEDATE, B.FMATERIALID,C.FPRICE ,A1.FPRDORGID) AS rn
, B.FMATERIALID, A1.FPRDORGID,B.Fname as 物料名称 , B.FSPECIFICATION as 规格,C.FACTUALQTY as 材积,
C.FPRICE,C.FACTUALQTY*C.FPRICE AS FCOUNT,A1.FDATE
from T_SP_PICKMTRLDATA c
INNER JOIN T_BD_MATERIAL_L B on C.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_PICKMTRL A1 ON C.FID = A1.FID
WHERE B.FNAME LIKE '%方%'
GROUP BY A1.FDATE,B.FSPECIFICATION ,C.FACTUALQTY ,B.FNAME ,C.FPRODUCEDATE, B.FMATERIALID,C.FPRICE ,A1.FPRDORGID
HAVING A1.FDATE = '2016-10-01 00:00:00.000'
)M INNER JOIN (
SELECT ROW_NUMBER()OVER( PARTITION BY FPRDORGID ORDER BY B.FMATERIALID,B.FSPECIFICATION,A1.FPRDORGID,A1.FDATE) AS rn
,B.FMATERIALID , B.FSPECIFICATION as 规格, SUM(A.FREALQTY) as 材积,A1.FPRDORGID ,A1.FDATE
FROM T_SP_INSTOCKENTRY A
INNER JOIN T_BD_MATERIAL_L B on A.FMATERIALID = B .FMATERIALID
INNER JOIN T_SP_INSTOCK A1 ON A1.FID = A.FID
WHERE B.FNAME like '湿刨切表板'
GROUP BY B.FMATERIALID,B.FSPECIFICATION,A1.FPRDORGID,A1.FDATE
HAVING A1.FDATE = '2016-10-01 00:00:00.000'
)N ON M.FPRDORGID = N.FPRDORGID AND m.rn=n.rn
#2
您好,谢谢您恢复我的问题,但是这样出来的结果 就是第一行了
#3
我看的想要的不就是右表满足条件的记录不重复输出吗?
)M INNER JOIN (
这里要改成LEFT JOIN 我上面疏忽了