怎样用left join 可保证右表唯一? select a.id,sum(a.sl*b.jg) from a left join b on a.id=b.a_idgroup by a.id右表b会有重复记录,怎么去掉重复的记录? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select a.id,sum(a.sl*T.jg) from a left join (select distinct * from b )T on a.id=T.a_idgroup by a.id select a.id,sum(a.sl*b.jg) from a left join (select distinct * from b)b on a.id=b.a_idgroup by a.id select a.id,a.sl*b.jgfrom (select id,sum(sl) sl from a group by id) a left join (select a_id,sum(jg) jg from b group by a_id) b on a.id=b.a_id select a.id,a.sl*b.jgfrom a left join (select a_id,sum(jg) jg from b group by a_id) b on a.id=b.a_id如果只有是B表有重复,只需这样。 select a.id, sum(a.sl * c.jg)from a left join (select distinct a_id,jq from b) con a.id = c.a_idgroup by a.id 表xfid product_h sl 1 P001 12 P002 23 P001 3表jgid product_h sl1 P001 102 P001 203 P002 30select a.product_h,a.sl from xf aleft join jg b on a.product_h=b.product_h结果是product_h slP001 1.00P001 1.00P002 2.00P001 3.00P001 3.00我想要只显示表xf的记录,不管有没有重复不要表jg的重复记录P001 1.00P001 1.00P002 2.00 SQL数据库秘籍 【大型数据库设计问题抉择!】 一个数据同期比较的问题,难了点哦 procedure的问题? 有没有能够在xp上安装服务器端的sql server2000? 一个考核计算的问题,急求~~~~~~~~~~~~~ 谢谢各位老大了 超级菜鸟求助:ADOQuery中的parameters问题 定义触发器 sql中这种需求的查询如何做 !关于log文件! 请问子句怎么sum呢? 关于取top前几条记录的问题,这个比较复杂
group by a.id
from a
left join (select distinct * from b)b on a.id=b.a_id
group by a.id
from (select id,sum(sl) sl from a group by id) a
left join (select a_id,sum(jg) jg from b group by a_id) b
on a.id=b.a_id
from a
left join (select a_id,sum(jg) jg from b group by a_id) b
on a.id=b.a_id如果只有是B表有重复,只需这样。
select
a.id,
sum(a.sl * c.jg)
from a
left join (select distinct a_id,jq from b) c
on a.id = c.a_id
group by a.id
id product_h sl
1 P001 1
2 P002 2
3 P001 3表jg
id product_h sl
1 P001 10
2 P001 20
3 P002 30select a.product_h,a.sl
from xf a
left join jg b on a.product_h=b.product_h
结果是
product_h sl
P001 1.00
P001 1.00
P002 2.00
P001 3.00
P001 3.00我想要只显示表xf的记录,不管有没有重复
不要表jg的重复记录
P001 1.00
P001 1.00
P002 2.00