mysql gender_mysql query to check if gender selected all

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed last month.

Improve this question

Hello In my application I wanted to show the ads to the users depending on the audience selected by the advertiser. at the moment I am saving gender to each user in the user database. The ads work best if the user selects gender male or female. But I don't know how I can modify the query if the user selected all as an audience.

I have two tables. Promotion and audience. This is how I am querying at the moment

SELECT p.id

, v.id

, a.id

, a.user_id

, a.name

, a.min_age

, a.max_age

, a.gender

, a.created

FROM promotion p

LEFT

JOIN video v

ON v.id = p.video_id

LEFT

JOIN audience a

ON a.id = p.audience_id

WHERE p.user_id != 17

AND a.gender = 'Male'

what I am intended to do is that if the gender value in the Audience table is saved as all then It shouldn't check male or female in the query. It should get all the records irrespective of the fact the user is male or female

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

Are you looking for something like this?

WHERE ....

AND `Audience`.`gender` IN ('All', ?)

The question mark represents the parameter to the query, that corresponds to the user's gender. It may take value 'Male' or 'Female'. If audiences stored gender is 'All', the condition always matches, regardless of the parameter given.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值