0

我有两张桌子:

Travellers_Report

Name    Country Place_of_visit  Return_date
A   United States   Los Angeles 2/27/2013
B   United Arab Emirates    DUBAI   2/21/2013
C   Puerto Rico San Juan    2/28/2013
D   United States   Los Angeles 2/27/2013
E   United States   Boston  2/27/2013
F   Malaysia    Kulalampur  3/1/2013
G   United Arab Emirates    DUBAI   2/15/2013
H   Malaysia    Kulalampur  3/15/2013
I   United States   Los Angeles 2/27/2013

公司_存在

Country City
United States   Los Angeles
United Arab Emirates    DUBAI
United States   Boston

我需要将“Travellers_Report”表的“Place_of_visit”字段与“Company_presence”表的“City 字段”进行比较并获取计数。

预期输出为:

Country               Place_of_visit    Count
United States         Los Angeles       3
United Arab Emirates  DUBAI             2
United States         Boston            1

截至目前,我在下面有两个查询,但我不知道如何将它们组合起来以获得预期的结果。

sqlstr = "SELECT * " & _
  "FROM Travellers_report " & _
  "WHERE Travellers_report.Return_Date >= #" & DOI & "# AND    
Travellers_report.Return_Date <=#" & tempd & "#;"

SELECT Travellers_report.Place_of_Visit, count(1) FROM Travellers_report 
GROUP BY Place_of_Visit
4

2 回答 2

0
SELECT  a.Country, a.City, COUNT(b.Place_of_visit) totalCount
FROM    Company_Presence a
        LEFT JOIN Travellers_Report b
            ON  a.Country = b.Country AND
                a.City = b.Place_of_visit AND
                b.return_DATE BETWEEN #date1_HERE# AND #date2_HERE#
GROUP   BY a.Country, a.City
于 2013-02-28T05:58:45.217 回答
0

@kiran 试试这个...
SELECT c.country,c.city,count(*) from company_presence as c,Travellers_Report as t where t.city=c.city group by c.city;

于 2013-02-28T06:06:20.977 回答