在sql中加入表 [英] Joining Table In sql

查看:90
本文介绍了在sql中加入表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人请帮我加入这2张桌子





表A

--- ------

id |优先|状态|姓名

---------------------------------

1 1 3 xyz

2 2 4 MMM





表B



Id |输入|钥匙

-------------------------

1优先权紧急

2优先|低价

3状态开启

4状态|关闭







我想要结果为,

结果

__________



Id |优先|状态|姓名

_______________________________

1紧急开放XYZ

2低关闭MM







请帮助... /

Any one please help me to join this 2 tables


Table A
---------
id | Priority | Status | Name
---------------------------------
1 1 3 xyz
2 2 4 MMM


Table B

Id | Type | Key
-------------------------
1 PRIORITY Urgent
2 Priority | LOW
3 STATUS Open
4 STATUS | Close



I want the result as ,
Result
__________

Id | Priority | Status | Name
_______________________________
1 URGENT OPEN XYZ
2 LOW CLOSE MM



Please Help .../

推荐答案

SELECT A.Id, B1.Priority, B2.Status, A.Name
FROM A
INNER JOIN B as B1 ON B1.Id = A.Priority
INNER JOIN B as B2 ON B2.Id = A.Status;





我应该添加这是Microsoft SQL Server(T-SQL)。它在大多数SQL语言(Oracle,MySql)中可能非常相似,但我不能肯定地说。



为了改善您的问题,请说明数据库类型/ version etc。



I should add this is Microsoft SQL Server (T-SQL). It's probably very similar in most SQL languages (Oracle, MySql) but I can't say for sure.

To improve your question in future, please state the Database type/version etc.


这篇关于在sql中加入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆