我有一个问题,我尝试使用以下信息从数据库检索用户的数据:
我需要的是购买产品的客户的名字、姓氏和电子邮件,引用号为 1800 和 1898。 2018年5月18日之前。
我尝试过这个查询:
select
ps_customer.firstname, lastname , email
from
ps_customer
inner join
ps_product
where
ps_product.reference in (1800,1898) and ps_product.date_add >= 2018-05-18
但这只返回了所有客户的所有信息,而这不是我想要的。
最佳答案
我宁愿使用两个表共有的唯一键将 ps_product 表连接到 ps_customer 表(无论是客户 ID 还是产品 ID,取决于两个表中可用的列),并且然后将我的限制放在一个单独的 where 子句中。还将日期放在 单引号 中的 where 子句中:
例如。
select ps_customer.firstname, lastname , email
from ps_customer c
inner join ps_product p on c.customerid = p.customerid
where ps_product.reference in (1800,1898) and ps_product.date_add >= '2018-05-18';
关于mysql - 数据库查询选择客户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52734381/