gpt4 book ai didi

mysql - 使用 UNION 和 DISTINCT 优化 MySQL 选择查询

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:12 27 4
gpt4 key购买 nike

我的 PHP 脚本中有一个查询没有返回所需的数据。查询是

select distinct require_category from users_require

返回:

Diet
Experience
MeasurementsGain
MeasurementsLoss
MeasurementsMaintain
WeightGain
WeightLoss
WeightMaintain
Workout

但我只想

Diet
Experience
MeasurementsGain
WeightGain
Workout

我已经改进了我的 mysql 查询并返回了正确的结果,但我认为它的效率不够高:

select distinct require_category from users_require where require_category NOT LIKE '%Weight%' and require_category NOT LIKE '%Measurements%' union select distinct require_category from users_require where require_category = 'WeightGain' or require_category = 'MeasurementsGain'

最佳答案

请尝试以下,

SELECT DISTINCT
require_category FROM users_require WHERE require_category NOT LIKE '%Loss%'
AND require_category NOT LIKE '%Maintain%'

关于mysql - 使用 UNION 和 DISTINCT 优化 MySQL 选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888538/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com