很简单的两张表,要求写出 SQL 语句,解决就送分,时间紧迫!!

khler 2008-03-04 12:14:18

两张表如下:
t1{f1[char],f2[int]} t2{f3[char],f1[char]}
A 6 X A
B 7 Y B
A 10 Z C

结果:
X 16
Y 7
Z 0

要求写出SQL语句得到如上结果。

...全文
180 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhou969 2008-03-17
  • 打赏
  • 举报
回复
select t2.f3,isnull((select sum(f2) from t1 where t1.f1=t2.f4),0)
from t2
lovemegigi 2008-03-09
  • 打赏
  • 举报
回复
select t2.f3, isnull((select sum(f2) from t1 where t1.f1=t2.f4),0) as f5 from t2
liuyufeng 2008-03-05
  • 打赏
  • 举报
回复
select sum(isnull(t1.f2 ,0)),t2.f3
from t1 full outer join t2 on t1.f1 = t2.f1
WeekWant 2008-03-05
  • 打赏
  • 举报
回复
不好意思,color=#FF0000]order by t1.f3[char][[/color], 应该为group by t1.f3
WeekWant 2008-03-05
  • 打赏
  • 举报
回复
select t1.f3[char],isnull(count(f2[int]),'0') from t1 inner join t2 where t1.f1[char] = t2.f1[char] order by t1.f3[char]
khler 2008-03-04
  • 打赏
  • 举报
回复
echeng192,过来领取
  • 打赏
  • 举报
回复
select t2.f3,
isnull((select sum(f2) from t1 where t1.f1=t2.f4),0) as f5
from t2
wjpath23 2008-03-04
  • 打赏
  • 举报
回复
---------------
create table t1(f1 char(10),f2 int)
insert into t1
select 'A',6
union all
select 'B',7
union all
select 'A',10
create table t2 (f3 char(10),f1 char(10))
insert into t2
select 'X','A'
union all
select 'Y','B'
union all
select 'z','C'
------------
select sum(isnull(dbo.t1.f2 ,0)) as b,dbo.t2.f3
from dbo.t1 full outer join dbo.t2
on dbo.t1.f1 = dbo.t2.f1
group by dbo.t2.f3
------------
---------------
create table t1(f1 char(10),f2 int)
insert into t1
select 'A',6
union all
select 'B',7
union all
select 'A',10
create table t2 (f3 char(10),f1 char(10))
insert into t2
select 'X','A'
union all
select 'Y','B'
union all
select 'z','C'
------------
16 X
7 Y
0 z
wjpath23 2008-03-04
  • 打赏
  • 举报
回复
---------------
create table t1(f1 char(10),f2 int)
insert into t1
select 'A',6
union all
select 'B',7
union all
select 'A',10
create table t2 (f3 char(10),f1 char(10))
insert into t2
select 'X','A'
union all
select 'Y','B'
union all
select 'z','C'
------------
select sum(isnull(dbo.t1.f2 ,0)) as b,dbo.t2.f3
from dbo.t1 full outer join dbo.t2
on dbo.t1.f1 = dbo.t2.f1
group by dbo.t2.f3
wwwwb 2008-03-04
  • 打赏
  • 举报
回复
select t2.f3,iif(isnull(sum(t1.f2)),0,sum(t1.f2)) from t2 inner join t1 on t1.f1=t2.f1
group by t2.f3
wwwwb 2008-03-04
  • 打赏
  • 举报
回复
select t2.f3,iif(isnull(sum(t1.f2)),0,sum(t1.f2)) from t2 inner join t1 on t1.f1=t2.f1

6,108

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据库报表
社区管理员
  • 数据库报表社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧