易截截图软件、单文件、免安装、纯绿色、仅160KB

求一个SQL查询 - MS-SQL Server / 应用实例

表A
字段a 字段b
01 a
02 b
03 c
04 d

表B
字段a 字段c 字段X  
01 a001 1
01 a002 2
01 a003 3
02 b001 1
02 b002 2
02 b003 3
03 c001 1
03 c002 2
03 c003 3
04 d001 1
04 d002 2
04 d003 3

求查询结果为
01 a a001 a002 a003
02 b b001 b002 b003
03 c c001 c002 c003
04 d d001 d002 d003

sql 查询代码如何写 谢谢~
字段X 固定是3个吗?

select a.*,
  max(case b.x when 1 then b.c else '' end) [1],
  max(case b.x when 2 then b.c else '' end) [2],
  max(case b.x when 3 then b.c else '' end) [3]
from a , b
where a.a = b.a 
group by a.a a.b



select a.*,
  max(case b.x when 1 then b.c else '' end) [1],
  max(case b.x when 2 then b.c else '' end) [2],
  max(case b.x when 3 then b.c else '' end) [3]
from a , b
where a.a = b.a 
group by a.a ,a.b


SQL code:
----------------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-05-19 15:50:56
-- Version: Microsoft SQL Server 2008 (RTM) -


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号