很简单的两张表,要求写出 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语句得到如上结果。

...全文
111 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
基于java的企业人事管理系统设计--软件工程课程设计(含源码与论文设计).rar 1 引言 4 1.1 课程设计目标 4 1.2 编程工具(编程环境)介绍 4 1.3 实施时间及主要实施步骤 4 2 需求析 5 3 系统总体设计 6 4 数据库设计 6 5 主要功能模块的设计与实现 10 5.1 功能模块1详细设计(综合查询员工信息)..........................................................10 5.1.1 详细设计.......................................................................................................10 5.1.2 算法流程........................................................................................................15 5.1.3 界面设计及测试结果.....................................................................................15 6 调试析 15 7 用户手册 16 8 测试结果 17 8.1 员工信息的添加...................................................................................................17 8.2 员工信息的修改...................................................................................................17 8.3 员工信息的删除...................................................................................................18 8.4 员工信息的综合查询...........................................................................................18 8.5 员工信息按性别统计的结果................................................................................19 8.6 员工信息按状态统计的结果...............................................................................19 8.7 员工信息按职称统计的结果................................................................................20 9 结论 20 10 参考文献 20
发帖
数据库报表
创建于2007-09-28

6095

社区成员

其他数据库开发 数据库报表
申请成为版主
帖子事件
创建了帖子
2008-03-04 12:14
社区公告
暂无公告