求一条SQL语句 - MS-SQL Server / 基础类
现有
表A 表B
id name firid secid thiid
1 军1 1 3 5
2 军2 1 3 6
3 师1 2 4 7
4 师2
5 旅1
6 旅2
7 旅3
想得到如下结果
fir sec thi
军1 师1 旅1
军1 师1 旅2
军2 师2 旅3
怎样实现呢?谢谢!
SQL code:
SELECT A1.[NAME],A2.[NAME],A3.[NAME]
from B
INNER JOIN A A1 ON B.FIR=A1.ID
INNERJ OIN A A2 ON B.SEC=A2.ID
INNER JOIN A A3 ON B.THI=A3.ID
SQL code:
SELECT A1.[NAME],A2.[NAME],A3.[NAME]
from B
INNER JOIN A A1 ON B.FIR=A1.ID
INNER JOIN A A2 ON B.SEC=A2.ID
INNER JOIN A A3 ON B.THI=A3.ID
测试
SQL code:
create table ta (id int,name varchar(3))
insert ta
select 1 ,'军1' union all
select 2 ,'军2' union all
select 3 ,'师1' union all
select 4 ,'师2' union all
select 5 ,'旅1' union all
select 6 ,'旅2' union all
select 7 ,'旅3'
create table tb(firid int, secid int,thiid int)
insert tb
select 1,3,5 union all
select 1,3,6 union all
select 2,4,7
select t1.name fir,t2.name sec,t3.name thi
from tb,ta t1
相关问答:
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
请教高手:
以下是数据库中的三条记录,英文为字段名称
id planname TaskBeginTime Status
329 2010年03 ......