要在SIngle行中显示的SQL查询 [英] SQL Query to Display in SIngle Row

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

问题描述





我有一张桌子如下



BaseTable

Id姓名TotalMember



1 ABC 2

2 DEF 1



DetailTable

ID名称地址

1 TestMm测试

1 Memeber2 test1

2 DEFMem添加





来自我需要的两张桌子

决赛桌



as

ID名称总会员Member1Name Member1Addrss Member2Name会员2Addrss

1 ABC 2 TestMm测试Memeber2 test1

2 DEF 1 DEFMem添加


帮我查询sql查询这个



谢谢

解决方案

请看看



http: //www.w3schools.com/sql/sql_join_inner.asp [ ^ ]



你想加入两张桌子的内容?

然后你必须使用INNER JOIN


你好,

我有一个问题给你。你有TotalMember超过2吗?如果你的答案是肯定的,那么如果你想在结果栏上代表所有成员的姓名,来自DetailTable的地址,你总是需要更改查询以获得所有成员姓名和地址的详细信息。



以下是我给你的解决方案,使用BaseTable和DetailTable之间的内部连接,根据ID列匹配两个表。



 选择 BT.ID,BT.Name,BT.TotalMember,DT.Name,DT.Address 
BaseTable as BT
内部 join DetailTable AS DT
ON BT。 ID = DT.ID;





此查询生成以下结果:

 ID名称TotalMember名称地址
1 ABC 2 TestMm测试
1 ABC 2 Member2测试1
2 DEF 1 DEFMem添加


Hi,

I have a table as below

BaseTable
Id Name TotalMember

1 ABC 2
2 DEF 1

DetailTable
ID Name Addrss
1 TestMm Test
1 Memeber2 test1
2 DEFMem Add


from Thse two table i need
Final Table

as
ID Name Total Member Member1Name Member1Addrss Member2Name Member2Addrss
1 ABC 2 TestMm test Memeber2 test1
2 DEF 1 DEFMem Add

Help me with sql query to achive this

Thanks

解决方案

Please have a look at

http://www.w3schools.com/sql/sql_join_inner.asp[^]

You want to join the contents of two tables?
Then you must use INNER JOIN


Hi,
I have a question for you. Can you have TotalMember more than 2? If your answer is yes, then if you want to represent all the member's name, address from DetailTable on result column you always have to change the query to get the all member name and address details.

Here is the solution I have for you is, using the Inner Join between BaseTable and DetailTable, matching the two tables based on ID column.

select BT.ID, BT.Name,BT.TotalMember, DT.Name, DT.Address
From BaseTable as BT
    Inner join DetailTable AS DT
    ON  BT.ID=DT.ID;



This query generates the following result:

ID	Name	TotalMember	Name	Address
1	ABC	2	TestMm	Test
1	ABC	2	Member2	Test1
2	DEF	1	DEFMem	Add


这篇关于要在SIngle行中显示的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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