求一条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
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......