查询合并需要计数的结果
Query to merge results that require count
问题陈述-
我有两个 table 'Location' 和 'Visit'。
在 table 'Location' 中,我有关于城市、国家、邮政编码等的详细信息,在 'Visit' 中,我有关于在 [=35= 中提到的地点进行了多少次访问的详细信息] table.
下面是两个table的列值-
地点Table
ID|City Name|Country Name|Zip Code|
访问Table
ID|Visit Date|Visit End Date|Visit Type|
问题-我想计算针对特定国家和特定访问类型完成的访问总数(基于 Visit [= 中访问类型列的值) 37=]).
通常,通过获取访问中的总行数 table 并使用 'ID' 列作为连接它们的键,这将是直接的。除此之外我希望结果显示如下-
##结果
Country Name|Total no of Visits|
这就是让我陷入困境的原因。我不确定如何在此处获取国家/地区名称以及行的计数值。
了解 ID
是连接两个表的公共属性,您可以通过操作进行简单的分组...
select
[Country Name],
count(*)
from location l
join visit v
on l.id = v.id
group by [Country Name]
如果您想按 Country Name
和 Visit Type
拆分计数,您必须将其添加到查询中并按此字段分组,但输出不会像您描述的那样
select
[Country Name],
[Visit Type],
count(*)
from location l
join visit v
on l.id = v.id
group by [Country Name],[Visit Type]
问题陈述-
我有两个 table 'Location' 和 'Visit'。 在 table 'Location' 中,我有关于城市、国家、邮政编码等的详细信息,在 'Visit' 中,我有关于在 [=35= 中提到的地点进行了多少次访问的详细信息] table.
下面是两个table的列值-
地点Table
ID|City Name|Country Name|Zip Code|
访问Table
ID|Visit Date|Visit End Date|Visit Type|
问题-我想计算针对特定国家和特定访问类型完成的访问总数(基于 Visit [= 中访问类型列的值) 37=]). 通常,通过获取访问中的总行数 table 并使用 'ID' 列作为连接它们的键,这将是直接的。除此之外我希望结果显示如下-
##结果
Country Name|Total no of Visits|
这就是让我陷入困境的原因。我不确定如何在此处获取国家/地区名称以及行的计数值。
了解 ID
是连接两个表的公共属性,您可以通过操作进行简单的分组...
select
[Country Name],
count(*)
from location l
join visit v
on l.id = v.id
group by [Country Name]
如果您想按 Country Name
和 Visit Type
拆分计数,您必须将其添加到查询中并按此字段分组,但输出不会像您描述的那样
select
[Country Name],
[Visit Type],
count(*)
from location l
join visit v
on l.id = v.id
group by [Country Name],[Visit Type]