使用 INNER JOIN 在 SQL 查询中出错

Getting error in SQL query using INNER JOIN

我还在学习MySQl。 这是关系型 DBMS :

CUSTOMER (CustID, CustName, AnnualRevenue)
TRUCK (TruckNumber, DriverName)
CITY (CityName, Population)
SHIPMENT (ShipmentNumber, CustID, Weight, Year, TruckNumber, CityName)

现在,我必须为这两个查询制定公式:

  1. Total weight of shipments per year for each city.
  2. Drivers who drove shipments to London but not Paris.

这些是我提出的查询: 1.

select sum(s.weight), s.year , c.city
from shipment s, city c
INNER JOIN CITY
on s.CityName = c.CityName

您正在混合使用旧方法来 JOIN table(您应该避免使用这种方法,因为没有明确说明连接列,这会让其他人感到困惑):

FROM shipment s, city c

您应该将 select 中未聚合的列分组(年份、城市)。此外,最好为聚合列使用别名 (AS total_weight)

select sum(s.weight) AS total_weight, s.year , c.city
from shipment s
INNER JOIN CITY as c
on s.CityName = c.CityName
GROUP BY s.year, c.city

尝试解决第二个问题,有问题再回来。