项目 - Id、名称、
PurchaseLog - Id、ItemId、CustomerId、PurchaseDate 用户 - Id、用户名
对于给定的两个客户的用户名,找到他们去年购买的常见物品的名称。
这是幼稚的(甚至是正确的)吗?:
select distinct item.id, item.name
from item i, PurchaseLog log_username1, PurchaseLog log_username2, user user1, user user2
where lower(user1.username) = lower('UserName1') AND
lower(user2.username) = lower('UserName2') AND
log_username1.itemid = log_username2.itemid AND
log_username2.itemid = i.itemid AND
log_username1 >-- satisfy date contraint AND
log_username2 >-- satisfy date contraint