Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mysql在单个查询中执行多个查询_Php_Mysql - Fatal编程技术网

Php 使用mysql在单个查询中执行多个查询

Php 使用mysql在单个查询中执行多个查询,php,mysql,Php,Mysql,我有两个问题。一个是总销售额,另一个是净销售额。我想在一个查询中报告。我该怎么做 总销售额 Location Name Gsale (sub-dealer-temp) 2 2049 (Sub-Dealer) Always Protected, LLC 3 2052 (Sub-Dealer) Alert Security,

我有两个问题。一个是总销售额,另一个是净销售额。我想在一个查询中报告。我该怎么做

总销售额

Location Name                                     Gsale 
(sub-dealer-temp)                                   2   
2049 (Sub-Dealer) Always Protected, LLC             3   
2052 (Sub-Dealer) Alert Security, Inc               4   
2055 (Sub-Dealer) Alarm Connection, LLC             5   
2067 (Sub-Dealer-t) Activation Dept, LLC            67  
2068 (Sub-Dealer-t) Premier Security USA, LLC       8   
净销售额

location Name                                     Nsale 
2055 (Sub-Dealer) Alarm Connection, LLC             5   
2067 (Sub-Dealer-t) Activation Dept, LLC           67   
2068 (Sub-Dealer-t) Premier Security USA, LLC       8   
2783 ((Sub-Dealer-t) Premier abc                    45  
2783 ((Sub-Dealer-t) Premier xyz                    32  
结果

Lc.Name                                Gsale             Nsale
(sub-dealer-temp)                        2               null
2049 (Sub-Dealer) Always Protected, LLC  3               null
2052 (Sub-Dealer) Alert Security, Inc    4               null
2055 (Sub-Dealer) Alarm Connection, LLC  5                5
2067 (Sub-Dealer-t) Activation Dept, LLC 67               67
2068 (Sub-Dealer-t) Premier Security US  8                8
2783 ((Sub-Dealer-t) Premier abc        null              45
2783 ((Sub-Dealer-t) Premier xyz        null              32

您可以使用下面的联接或联合来进行联接查询

     select g.location,g.name,g.Gsale,n.Nsale from gross sale g 
     join net sale n on g.location=n.location

您可以使用以下sql代码:

表名1:销售总额现在是
Gross\u Sale
和列名
lcName
Gsale

SELECT a.lcName, a.Gsale, b.Nsale FROM gross_sale a 
FULL OUTER JOIN net_sale b ON a.lcName=b.lcName ORDER BY a.lcName;
表名2:净销售额现在是
Net\u Sale
和列名
lcName
Nsale

SELECT a.lcName, a.Gsale, b.Nsale FROM gross_sale a 
FULL OUTER JOIN net_sale b ON a.lcName=b.lcName ORDER BY a.lcName;

提示:
UNION
请学习设置垂直块的格式。您想要一个完整的外部连接,而不是左连接右连接?请看列
Gsale
?@Drew您能解释清楚吗?左连接做什么?@Drew很抱歉,是的,它将完全外部连接。