求连接SQL语句 谢谢 - MS-SQL Server / 应用实例
表A
ORDER, DATETIME, QTY
B00056, 5/11/2010,100
B00056, 5/12/2010,200
B00056, 5/13/2010,300
求静态SQL语句实现如下效果,谢谢
ORDER, REMARK
B00056, 5/11/2010 100,5/12/2010 200,5/13/2010 300
http://topic.csdn.net/u/20080805/08/aa1cc594-fe80-4bac-8e40-e1ece2d3a78d.html
SQL code:
----------------------------------------------------------------
-- Author :SQL77(只为思齐老)
-- Date :2010-05-12 21:43:37
-- Version:
-- Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
-- Oct 14 2005 00:33:37
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
----------------------------------------------------------------
--> 测试数据:#5B
if object_id('tempdb.dbo.#TB') is not null drop table #TB
go
create table #TB([ORDER] varchar(6),[DATETIME] VARCHAR(10),[QTY] int)
insert #TB
select 'B00056','5/11/2010',100 union all
select 'B00056','5/12/2010',200 union all
select 'B00056','5/13/2010',300
--------------开始查询--------------------------
select DISTINCT [ORDER],stuff((select ','+[DATETIME]+' '+LTRIM([QTY])
from #TB
where [ORDER]=a.[ORDER] for xml path('')
),1,1,'') as [values]
from #TB a
----------------结果----------------------------
/*
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
需求如下:
学院 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 ......