SQL:除了加入多个查询外

时间:2018-03-16 18:28:24

标签: sql join

尝试构建此查询时遇到了一点困难。 (SQL SERVER)

我试图在类似的行上连接两个表,但是然后在结果集上堆叠表1和表2中的唯一行。我是第一次拍摄完整的外部连接,但是当数据仅来自其中一个表格时,它会将我的关键字段留空。

示例: Full Outer Join

以下是我希望查询能够执行的操作:

Joining And Stacking Tables

基本上,我想有一个结果表,其中关键字段(部分和操作)都在两列中返回(所以像一个联合),但是Estimated和Actual Rate列并排返回,其中有一个匹配表1和表2之间的行。

我也一直在尝试内连接两个表来创建一个子查询,然后在每个表上使用该内连接用于except子句,然后将原始内连接与两个除了联合之外。

当前尝试: One Join, Two Excepts, Two Unions

更新:我当前尝试返回值!虽然它有点复杂,但感谢任何建议或反馈!下面的好答案谢谢,我需要做一些比较

由于

2 个答案:

答案 0 :(得分:2)

SELECT ISNULL(t1.part,t2.part) AS Part,
       ISNULL(t1.operation,t2.operation) AS Operation,
       ISNULL('Estimated Rate',0) AS 'Estimated Rate',
       ISNULL('Actual Rate',0) AS 'Actual Rate'
FROM table1 t1
FULL OUTER JOIN table2 t2
  ON t1.part = t2.part
 AND t1.operation = t2.operation

答案 1 :(得分:0)

我会以session_start(); // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys require_once('stripe-php/init.php');// add the php library for stripe \Stripe\Stripe::setApiKey("sk_test_8UDgizhVo91Z8MJqk7G9n9BN"); // Token is created using Checkout or Elements! // Get the payment token ID submitted by the form: $token = $_POST['stripeToken']; $amount=$_SESSION['amount']; // Charge the user's card: $charge = \Stripe\Charge::create(array( "amount" => $amount, "currency" => "usd", "description" => "Example charge", "metadata" => array("order_id" => 6735), "source" => $token, )); union all

来执行此操作
group by