内连接查询中的条件

时间:2018-05-07 16:48:26

标签: php mysql mysql-workbench

function processCCOrder($idCompany){

    $sql = "SELECT oi.order_items_qty * oi.order_items_price AS order_value,si.sales_item_qty * si.price AS invoice_price 
           FROM order_items oi,sales_items si
           where oi.product_idproduct = S.product_idproduct
           SELECT c.customer_name,op.*,s.salesNo,sp.salesperson_name,if(order_value != invoice_price)
           FROM ORDER_PRODUCT OP
           INNER JOIN customer c 
           ON op.customer_idcustomer = c.idcustomer
           INNER JOIN sales s
           ON op.idorder = s.order_idorder
           INNER JOIN sales_person sp
           ON op.idorder = sp.idsales_person
           WHERE oi.idcompany = $idCompany";

    return $sql;
}

在上面的代码中我尝试

  • 选择items_qty * item_price,这是新名称order_value
  • 选择sales_qty * sale_price它将它的新名称乘以invoice_value
  • 但是order_value&发票金额oi.product_idproduct = S.product_idproduct
  • 接下来检查是否(order_value!= invoice_price)确实
  • 选择值&执行此内部联接查询

0 个答案:

没有答案