从视图中取出不重复记录
五张表关联.
最后一张表为某个项目某个合同的支付情况!
SELECT TOP 100 PERCENT dbo.t_ProjItem.Item_name, dbo.t_ProjItem.Item_amount,
dbo.t_ProjCon.Con_name, dbo.t_ProjOrg.Org_name, dbo.t_ProjItem.Item_id,
dbo.t_ProjItem.Item_type, dbo.t_ProjPay.Pay_Contract,
dbo.t_ProjContract.Contract_account, dbo.t_ProjPay.Pay_id
FROM dbo.t_ProjItem INNER JOIN
dbo.t_ProjOrg ON dbo.t_ProjItem.Item_org = dbo.t_ProjOrg.Org_id INNER JOIN
dbo.t_ProjContract ON
dbo.t_ProjItem.Item_id = dbo.t_ProjContract.Contract_item INNER JOIN
dbo.t_ProjCon ON
dbo.t_ProjContract.Contract_con = dbo.t_ProjCon.Con_id INNER JOIN
dbo.t_ProjPay ON dbo.t_ProjContract.Contract_id = dbo.t_ProjPay.Pay_Contract
现在从这个视图中取记录,但是重复的.如何过滤掉重复记录.
------解决方案--------------------try
SELECT DISTINCT dbo.t_ProjItem.Item_name, dbo.t_ProjItem.Item_amount,
dbo.t_ProjCon.Con_name, dbo.t_ProjOrg.Org_name, dbo.t_ProjItem.Item_id,
dbo.t_ProjItem.Item_type, dbo.t_ProjPay.Pay_Contract,
dbo.t_ProjContract.Contract_account, dbo.t_ProjPay.Pay_id
FROM dbo.t_ProjItem INNER JOIN
dbo.t_ProjOrg ON dbo.t_ProjItem.Item_org = dbo.t_ProjOrg.Org_id INNER JOIN
dbo.t_ProjContract ON
dbo.t_ProjItem.Item_id = dbo.t_ProjContract.Contract_item INNER JOIN
dbo.t_ProjCon ON
dbo.t_ProjContract.Contract_con = dbo.t_ProjCon.Con_id INNER JOIN
dbo.t_ProjPay ON dbo.t_ProjContract.Contract_id = dbo.t_ProjPay.Pay_Contract
------解决方案--------------------如果select a,b,c,d from tb where group a,b,c,d
我只想按a筛选?怎么办.像这样,可是不行.
select a,b,c,d from tb where group a
--a 相同时取b最大的那条记录
select a,b,c,d from tb m where not exists(select 1 from tb where a=m.a and b> a.b)
------解决方案--------------------lz的重复是指全部重复还是部分字段重复? :)