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

求一条SQL语句

TableA


id name type company
1 小明 type_a 公司1
2 小王 type_b 公司1




TableB  
id type_a type_b type_c company
1 11 43 88 公司1
2 33 55 78 公司2

想得到的结果

id name type company
1 小明 11 公司1
2 小王 43 公司1
SQL code:
select a.id,a.name,b.type,b.company
from tablea a,tableb
where a.id=b.id



SQL code:
select a.id,a.name,b.type_a as type,a.company from table1 a join table2 on a.company=b.company
union all
select a.id,a.name,b.type_b as type,a.company from table1 a join table2 on a.company=b.company


1楼的简洁,好
1楼的简洁,好

SQL code:

select id, name,
case a.when 'type_a' then b.type_a when 'type_b' then b.type_b else type_c end, company
from tablea a,tableb b
where a.id=b.id



引用
SQL code
select a.id,a.name,b.type_a as type,a.company from tablea a join tableb on a.company=b.company
union all
select a.id,a.name,b.type_b as type,a.compa


相关问答:

求一sql语句 - MS-SQL Server / 疑难问题

现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

求一个SQL语句 - MS-SQL Server / 基础类

字段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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号