Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
要基于另一个查询计数的oracle sql查询_Sql_Oracle - Fatal编程技术网

要基于另一个查询计数的oracle sql查询

要基于另一个查询计数的oracle sql查询,sql,oracle,Sql,Oracle,我想知道哪个国家的客户订单最多。因此,我有一个sales\u表,其中包含customer\u id。但是country\u id在customer\u表中。所以我需要根据国家统计来计算客户数量。。。但是我不知道怎么做。我 我知道如何统计顾客 select count(cust_id) from sh_sales 如何计算国家 select count(country_id) from sh_customers 但我想根据sh\u销售表中最常用的customer\u id统计国家/地区 所以应

我想知道哪个国家的客户订单最多。因此,我有一个
sales\u表
,其中包含
customer\u id
。但是
country\u id
customer\u表中。所以我需要根据国家统计来计算客户数量。。。但是我不知道怎么做。我

我知道如何统计顾客

select count(cust_id)
from sh_sales
如何计算国家

select count(country_id)
from sh_customers
但我想根据
sh\u销售表中最常用的
customer\u id
统计国家/地区

所以应该是这样的

select count(country_id)
from sh_customers
where sh_sales.customer ????

这里我真的需要一些帮助:)

这将统计sh_sales表中的记录,并从customers表中按每个国家/地区id分组

SELECT country_id, count(s.cust_ID)
FROM sh_customers c
    INNER JOIN sh_sales s ON c.cust_id = s.cust_id
GROUP BY country_id

如果由于某种原因,您可能有一个客户记录,但没有销售,那么您可以使用
左外部联接
为没有任何销售的国家/地区返回空值

这将统计sh_sales表中的记录,并从customers表中按每个国家/地区id分组

SELECT country_id, count(s.cust_ID)
FROM sh_customers c
    INNER JOIN sh_sales s ON c.cust_id = s.cust_id
GROUP BY country_id

如果出于某种原因,您可能有一个客户记录,但没有销售,那么您可以使用
左外联接
为没有任何销售的国家返回空值

,因此现在它显示每个国家,并在其旁边显示该国的客户数,对吗?现在它向我显示了每个国家,旁边是这个国家的客户数量,对吗?