显示订购的所有产品名称以及客户的名字和姓氏的列表

Show the list of all product's names ordered along with first and last names of the customers

我正在做一个练习,但我一直坚持下去。有 2 个表:

查询:

SELECT Orders.product_name, Customers.firstname, Customers.lastname
FROM Orders INNER JOIN
     Customers
     ON Orders.id_customer=Customers.id
ORDER BY Orders.id;

预期结果:

显示订购的所有产品名称以及客户姓名的列表。

仅在结果中包含那些在数据库中没有地址的客户,并按 Orders.id 对数据进行排序。

看起来你很接近。您只需要一个 WHERE 子句来满足此要求:

Include to the result only those customers who has no address in a database

试试这个:

SELECT Orders.product_name, Customers.firstname, Customers.lastname
FROM Orders INNER JOIN Customers ON Orders.id_customer = Customers.id
WHERE address IS NULL OR address = ''
ORDER BY Orders.id;

再添加一个地址为空的条件

   SELECT Orders.product_name, 
     Customers.firstname, 
    Customers.lastname FROM Orders 
    INNER JOIN Customers ON 
    Orders.id_customer=Customers.id 
    and  Customers.address IS NULL
    ORDER BY Orders.id;