SQL选择合并多个表结果

时间:2012-02-09 19:06:06

标签: sql select

我想在多个表上运行select查询并合并结果。例如,我想将Last_month服务器可用性报告与current_month可用性报告合并。我有两个表Last_table1和current_table1

Last_table1
===========
Hosts    Availability
Server1      99.99%
Server2      87.55%


Current_table1
==============
Hosts    Availability
Server1     78.00%
Server2     100.00%

我想合并两个表,需要结果如下。我如何编写选择查询?

Hosts         Last       current
Server1      99.99%      78.00%
Server2      87.55%      100.00%

1 个答案:

答案 0 :(得分:1)

您需要执行JOIN,并在适当的位置显示正确的列:

SELECT 
  L.Hosts, L.Availability AS Last, C.Availability AS Current
FROM 
  Last_Table1 L
INNER JOIN 
  Current_Table1 C
ON 
  C.Hosts = L.Hosts