首页 新闻 会员 周边 捐助

sql语句问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2010-03-03 10:47

SELECT
CONVERT(varchar(10),t5.FDate,120)AS '日期' ,
t5.FBillNo AS '订单编号',
t4.FName AS '客户名称',
t6.fallamount AS '订单金额',
t1.fallamount AS '开票金额',
t2.FDate AS '发票',

t3.FPreAmountFor AS '预收款',
t3.FAmountFor AS '现金',
t8.FName AS '制单人',
t6.FAmount-t3.FPreAmountFor-t3.FPreAmountFor as '余额',
t6.FInterID,
t4.FItemID
FROM

ICSaleEntry t1,
ICSale t2,
t_RP_NewReceiveBill t3,
t_Organization t4,
SEOrder t5,
SEOrderEntry t6,
--dbo.t_rp_Exchange t7
dbo.t_User t8,
dbo.t_Department t9,
dbo.t_Currency t10

where
t1.FOrderInterID=t5.FInterID
AND t2.FInterID=t1.FInterID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
AND t3.fexplanation=t2.fnote
--AND t3.FBillID=t7.FBillID
AND t3.FPreparer=t8.FUserID
and t9.fitemId=t5.FDeptID
and t10.FCurrencyID=t5.FCurrencyID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID

 

查询FBillNo订单编号的结果有重复的,但是我只要显示一条出来,请问要把这条语句改成什么样子?

问题补充: 把SQL语句写好给我咯!谢谢,你说我也不知道要怎么改,我也不知道关系啊!2楼的sql语句不行啊!!distinct这个好像对字符串不起作用!没报错啊,就是显示的数据全是重复的啊!
°潶、緤°的主页 °潶、緤° | 初学一级 | 园豆:17
提问于:2010-03-01 15:29
< >
分享
所有回答(3)
0

你这个还真不好说啊,而且你的语句也太那个了,这么多表最起码应该有关联表关联字。

1、 可以用排重关键字 distinct 来排重。

2、用左右关联来指定主从表,逻辑上滤掉数据 left outer join、right outer join

邢少 | 园豆:10926 (专家六级) | 2010-03-01 15:37
0

你的那些表的关系一点介绍都没有,别人很难帮你找到问题!

试试这样吧!!

--------------------------

SELECT distinct
CONVERT(varchar(10),t5.FDate,120)AS '日期' ,
t5.FBillNo AS '订单编号',
t4.FName AS '客户名称',
t6.fallamount AS '订单金额',
t1.fallamount AS '开票金额',
t2.FDate AS '发票',

t3.FPreAmountFor AS '预收款',
t3.FAmountFor AS '现金',
t8.FName AS '制单人',
t6.FAmount-t3.FPreAmountFor-t3.FPreAmountFor as '余额',
t6.FInterID,
t4.FItemID
FROM

ICSaleEntry t1,
ICSale t2,
t_RP_NewReceiveBill t3,
t_Organization t4,
SEOrder t5,
SEOrderEntry t6,
--dbo.t_rp_Exchange t7
dbo.t_User t8,
dbo.t_Department t9,
dbo.t_Currency t10

where
t1.FOrderInterID=t5.FInterID
AND t2.FInterID=t1.FInterID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
AND t3.fexplanation=t2.fnote
--AND t3.FBillID=t7.FBillID
AND t3.FPreparer=t8.FUserID
and t9.fitemId=t5.FDeptID
and t10.FCurrencyID=t5.FCurrencyID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID

langford | 园豆:710 (小虾三级) | 2010-03-01 15:53
0

对于重复数据的查询,可能有两种情况,部分重复和完全重复。您的这种情况开应该属于后者.

参考处理办法:http://www.cnblogs.com/jianlinglo/archive/2009/03/07/1405355.html

如果楼主能够把查询的错误结果贴出来就更好了!

风影极光 | 园豆:1573 (小虾三级) | 2010-03-01 16:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册