我正在尝试检索符合以下条件的所有ID:
select id from Customer
join Address on Address.customer_id = Customer.id
join Orders on Orders.customer_id = Customer.id
join Gender on Gender.customer_id = Customer.id
join Telephone on Telephone.customer_id = Customer.id
where Address.street_name ='MainStreet'
and Orders.customer_id is not null
and Gender.gender ='Female'
group by Telephone.customer_id
having count(Telephone.customer_id) = 2
当我运行它时,我收到“列或表达式无效” 当我删除该组时,它可以正常工作。
有人可以帮我这个吗?
答案 0 :(得分:0)
试试这个
select id from Customer
join Address on Address.customer_id = Customer.id
join Orders on Orders.customer_id = Customer.id
join Gender on Gender.customer_id = Customer.id
join (
select customer_id from Telephone
group by customer_id
having count(customer_id) = 2
) AS Telephone on Telephone.customer_id = Customer.id
where Address.street_name ='MainStreet'
and Orders.customer_id is not null
and Gender.gender ='Female'