如何在SQL Server中组合两个表 [英] How to combine two table in SQL server

查看:97
本文介绍了如何在SQL Server中组合两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

农民登记表如下





农民名字区域区村庄



1055662 Lacina OUNGAlo Diawala Nord Diwala



交易表如下





transactionid数量价格支付到期



1055662 1 200 200 100



来自以上我想要的输出如下



farmerid名字区域区段数量价格支付

1055662 Lacina OUNGALo Diawala Nord 1 200 200





如何使用join并在sql server中获取上述输出



我是什么尝试过:



农民登记表如下





farmid名字地区区域村



1055662 Lacina OUNGAlo Diawala Nord Diwala < br $>


交易表如下





transactionid数量价格支付到期/>


1055662 1 200 200 100



从以上我想要的输出如下



farmerid名字区域区段数量价格支付

1055662 Lacina OUNGALo Diawala Nord 1 200 200





如何使用join并在sql server中获取上面的输出

farmerregistration table as follows


farmerid Firstname Region Zone Section Village

1055662 Lacina OUNGAlo Diawala Nord Diwala

transaction table as follows


transactionid Qty Price Paid Due

1055662 1 200 200 100

from the above i want output as follows

farmerid Firstname Region Zone Section Qty Price Paid
1055662 Lacina OUNGALo Diawala Nord 1 200 200


how to use join and get the above output in sql server

What I have tried:

farmerregistration table as follows


farmerid Firstname Region Zone Section Village

1055662 Lacina OUNGAlo Diawala Nord Diwala

transaction table as follows


transactionid Qty Price Paid Due

1055662 1 200 200 100

from the above i want output as follows

farmerid Firstname Region Zone Section Qty Price Paid
1055662 Lacina OUNGALo Diawala Nord 1 200 200


how to use join and get the above output in sql server

推荐答案

说,你有两张桌子

name_info(id int,name string);

visit_info(id int,entry_date date,departure_date date)



查询将是:

Say, you have two tables
name_info(id int, name string);
visit_info (id int, entry_date date, departure_date date )

The query would be:
SELECT a.id, a.name, b.id, b.entry_date, b.departure_date FROM name_info a, visit_info b WHERE a.id=b.id
-- or
SELECT a.id, a.name, b.id, b.entry_date, b.departure_date FROM name_info a JOIN visit_info b ON( a.id=b.id )





让我们知道这还不够。



Let us know if this is not enough.


这篇关于如何在SQL Server中组合两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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