如何在SQL Serever中获取数据两个表 [英] How to get data two tables in SQL Serever

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

问题描述

我有两个表在数据库中包含相同的字段。

一个表将包含数据..

第二个表将包含在表1..SRNO中更改的数据表1和表2中相同

现在我想要一个基于日期的报告。

如何检查两个表中选择的日期并获取所选日期的报告?

解决方案

假设您有两个表即table1和table2,查询将如下所示

 < span class =code-keyword> SELECT  t1.srNo,t1.Data  as  OLDData,t2.Data  as  ChangeData 
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t2.srno = t1.srno
WHERE t 1. date = YYYYMMDD t2.date = YYYYMMDD。


假设你有两个表,即table1和table2,查询将如下所示:


SELECT t1.srNo,t1.Data as OLDData, t2.Data as ChangeData

FROM table1 AS t1

INNER JOIN table2 AS t2

ON t2.srno = t1.srno

WHERE t1.date = YYYYMMDD或t2.date = YYYYMMDD。


I have two tables containing same fields in database.
One table will contain data..
2nd table will contain data which are changed in table 1..SRNO is same in table 1 and table 2
Now I want a report based on date.
How to check for the date selected in both tables and get report for the selected date?

解决方案

Suppose You have two table i.e. table1 and table2 the query will be as below

SELECT t1.srNo,t1.Data as OLDData,t2.Data as ChangeData  
FROM table1 AS t1
   INNER JOIN table2 AS t2
     ON t2.srno = t1.srno
WHERE t1.date = YYYYMMDD or t2.date=YYYYMMDD.


Suppose You have two table i.e. table1 and table2 the query will be as below

SELECT t1.srNo,t1.Data as OLDData,t2.Data as ChangeData
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t2.srno = t1.srno
WHERE t1.date = YYYYMMDD or t2.date=YYYYMMDD.


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

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