Если вы хотите исключить только тех потребителей, которым ровно 50 лет, вы можете использовать and age != 50
в своем предложении where.
create table consumer_details (
id int not null auto_increment,
age int not null,
purchase_count int not null,
gender varchar(10) not null,
primary key (id)
);
insert into consumer_details (age, purchase_count, gender) values(18, 99, 'female');
insert into consumer_details (age, purchase_count, gender) values(99, 101, 'male');
insert into consumer_details (age, purchase_count, gender) values(50, 101, 'female');
insert into consumer_details (age, purchase_count, gender) values(50, 99, 'male');
insert into consumer_details (age, purchase_count, gender) values(49, 99, 'female');
insert into consumer_details (age, purchase_count, gender) values(49, 101, 'male');
select *
from consumer_details
where age > 30
and age <> 50
and purchase_count > 100
order by gender desc;
Если вы хотите исключить всех потребителей, которые точно 50 лет AND имеют параметр buy_count ниже 100, который можно добавить для исключения подзапроса.
select *
from consumer_details
where age > 30 and purchase_count > 100
and id not in (
select id from consumer_details where age = 50 and purchase_count < 100
)
order by gender desc;
Fiddle with с расширенным условием where: http://sqlfiddle.com/#! 9 / d4bc5f / 1
Скрипка с подзапросом: http://sqlfiddle.com/#! 9 / 3701c2 / 4