1。查询一个两列表中一列相同另一列不同的记录:
设两列分别为a,b,表tbl则:
SELECT i_PO,s_idnumber,i_DepartmentID
FROM ksb_receive
WHERE s_idnumber IN
(SELECT s_idnumber FROM (SELECT s_idnumber,COUNT(i_departmentid) AS count1 FROM
(SELECT s_idnumber,i_departmentid
FROM ksb_receive GROUP BY s_idnumber,i_departmentID HAVING len(s_idnumber)>0) AS a
WHERE i_departmentid<>'' GROUP BY s_idnumber HAVING COUNT(i_departmentid)>1 )AS m )
GO
2。查询物料主表和收料表物料类别不同的记录(物料主表,收料表,关联表)
设主表为a,物料表b,关联表c。则:
SELECT m.IDNumber,m.FinMaterialType,n.s_FIMatType
FROM tblmmd m INNER JOIN
(SELECT s_idnumber,i_departmentid,s_FIMatType
FROM ksb_receive a INNER JOIN FI_FIMatType b ON a.i_departmentid = b.i_sort2
AND a.i_departmentid IN (1,2,3)) n
ON m.idnumber = n.s_idnumber AND m.FinMaterialType <> n.s_FIMatType
设两列分别为a,b,表tbl则:
SELECT i_PO,s_idnumber,i_DepartmentID
FROM ksb_receive
WHERE s_idnumber IN
(SELECT s_idnumber FROM (SELECT s_idnumber,COUNT(i_departmentid) AS count1 FROM
(SELECT s_idnumber,i_departmentid
FROM ksb_receive GROUP BY s_idnumber,i_departmentID HAVING len(s_idnumber)>0) AS a
WHERE i_departmentid<>'' GROUP BY s_idnumber HAVING COUNT(i_departmentid)>1 )AS m )
GO
2。查询物料主表和收料表物料类别不同的记录(物料主表,收料表,关联表)
设主表为a,物料表b,关联表c。则:
SELECT m.IDNumber,m.FinMaterialType,n.s_FIMatType
FROM tblmmd m INNER JOIN
(SELECT s_idnumber,i_departmentid,s_FIMatType
FROM ksb_receive a INNER JOIN FI_FIMatType b ON a.i_departmentid = b.i_sort2
AND a.i_departmentid IN (1,2,3)) n
ON m.idnumber = n.s_idnumber AND m.FinMaterialType <> n.s_FIMatType