加入两个数据透视表

时间:2017-03-20 12:47:16

标签: join pivot

我在MS SQL Server 2012中有两个查询:

**Query for Uploads:**    
select Contract_Code, [201612] as '201612',[201701] as '201701', [201702] as '201702' from (select OrderID, Creation_Date_YYYYMM, Contract_Code from Raw_Data_A) p
    pivot(count(OrderID) for Creation_Date_YYYYMM in ([201612],[201701],[201702])) as pvt
    order by Contract_Code


**Query for REal Orders:**    
select Contract_Code, [201612] as '201612',[201701] as '201701', [201702] as '201702' from (select OrderID, concat(year([Creation_Date]),format([Creation_date],'MM')) as Creation_Date_YYYYMM, Contract_Code from Raw_Data_B) p2
    pivot(count(OrderID) for Creation_Date_YYYYMM in ([201612],[201701],[201702])) as pvt
    order by Contract_Code

每个产生的结果如下:

Contract_Code   201612  201701  201702
Contract1   3   1   0
Contract2   17  0   6
Contract3   23  8   14
Contract4   48  45  6

我想加入他们以实现以下输出:

             201612     201701  201702  
ContractNameRealUploadRealUploadRealUpload
Contract1   23  24  35  26  27  28
Contract2   24  45  36  26  27  28
Contract3   25  45  37  26  27  28
Contract4   26  45  38  26  27  28
Contract5   27  45  39  26  27  28
Contract6   28  45  40  26  27  28
Contract7   29  45  41  26  27  28
Contract8   30  45  42  26  27  28
Contract9   31  45  43  26  27  28
Contract10  32  45  44  26  27  28
希望你能帮助我。感谢

1 个答案:

答案 0 :(得分:1)

它适用于以下代码:

System.setProperty("webdriver.firefox.marionette",System.getProperty("user.dir")+ "\\libs\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://accounts.google.com/ServiceLogin?");
UtilityMethods.sleep(5000);
driver.findElement(By.id("Email")).sendKeys("YourID");//Email ID
driver.findElement(By.id("next")).click();
UtilityMethods.sleep(5000);
driver.findElement(By.id("Passwd")).sendKeys("YourPassword");//Password
driver.findElement(By.id("signIn")).click();//Sign IN
UtilityMethods.sleep(20000);
System.out.println("Mail Opened");
UtilityMethods.sleep(20000);
System.out.println("Delete all check box is displayed :: "+driver.findElement(By.xpath("//div[@aria-label='Select']")).isDisplayed()+"");
System.out.println("Delete all check box is Enabled   :: "+driver.findElement(By.xpath("//div[@aria-label='Select']")).isEnabled()+"");
driver.findElement(By.xpath("//div[@aria-label='Select']")).click();//Delete All Check BOX
UtilityMethods.sleep(20000);
System.out.println("Check box selected");
System.out.println("Delete button is displayed :: "+driver.findElement(By.xpath("//div[@aria-label='Delete']")).isDisplayed()+"");
System.out.println("Delete button is Enabled   :: "+driver.findElement(By.xpath("//div[@aria-label='Delete']")).isEnabled()+"");
driver.findElement(By.xpath("//div[@aria-label='Delete']")).click();//Delete BUtton
UtilityMethods.sleep(20000);
System.out.println("Delete Button Clicked");