gpt4 book ai didi

mysql - 如何编辑我的 MySQL 请求最大大小写输出?

转载 作者:行者123 更新时间:2023-11-29 07:29:01 24 4
gpt4 key购买 nike

当我运行以下查询时。

SELECT tblhostingaddons.id as id, 
MAX(CASE WHEN (tblcustomfields.fieldname = 'boyut') THEN tblcustomfields.fieldoptions ELSE NULL END) AS quota,
MAX(CASE WHEN (tblcustomfields.fieldname = 'adet') THEN tblcustomfields.fieldoptions ELSE NULL END) AS pc,
MAX(CASE WHEN (tblcustomfields.fieldname = 'gonderimlimiti') THEN tblcustomfields.fieldoptions ELSE NULL END) AS send,
MAX(CASE WHEN (tblcustomfields.fieldname = 'turu') THEN tblcustomfields.fieldoptions ELSE NULL END) AS type
FROM `tblhostingaddons`
LEFT JOIN tbladdons ON tbladdons.id = tblhostingaddons.addonid
LEFT JOIN tblcustomfields ON tblcustomfields.relid = tbladdons.id
WHERE tblhostingaddons.hostingid = '88'
AND tblhostingaddons.status = 'Active'
GROUP BY tblhostingaddons.id
ORDER BY tblhostingaddons.id

出现以下结果。但我只希望 type 出现在 epostapro 的行中。

id quota pc     send type
74 5120 1 200 epostapro
75 NULL NULL NULL NULL

最佳答案

尝试使用 having 子句:

SELECT tblhostingaddons.id as id, 
MAX(CASE WHEN (tblcustomfields.fieldname = 'boyut') THEN tblcustomfields.fieldoptions ELSE NULL END) AS boyut,
MAX(CASE WHEN (tblcustomfields.fieldname = 'adet') THEN tblcustomfields.fieldoptions ELSE NULL END) AS adet,
MAX(CASE WHEN (tblcustomfields.fieldname = 'gonderimlimiti') THEN tblcustomfields.fieldoptions ELSE NULL END) AS gonderimlimiti,
MAX(CASE WHEN (tblcustomfields.fieldname = 'turu') THEN tblcustomfields.fieldoptions ELSE NULL END) AS turu
FROM `tblhostingaddons`
LEFT JOIN tbladdons ON tbladdons.id = tblhostingaddons.addonid
LEFT JOIN tblcustomfields ON tblcustomfields.relid = tbladdons.id
WHERE tblhostingaddons.hostingid = '88'
AND tblhostingaddons.status = 'Active'
GROUP BY tblhostingaddons.id
having MAX(CASE WHEN (tblcustomfields.fieldname = 'turu') THEN tblcustomfields.fieldoptions ELSE NULL END)='epostapro'
ORDER BY tblhostingaddons.id

或者您可以从选择列表中删除 id 以及分组依据如下所示:

SELECT  
MAX(CASE WHEN (tblcustomfields.fieldname = 'boyut') THEN tblcustomfields.fieldoptions ELSE NULL END) AS boyut,
MAX(CASE WHEN (tblcustomfields.fieldname = 'adet') THEN tblcustomfields.fieldoptions ELSE NULL END) AS adet,
MAX(CASE WHEN (tblcustomfields.fieldname = 'gonderimlimiti') THEN tblcustomfields.fieldoptions ELSE NULL END) AS gonderimlimiti,
MAX(CASE WHEN (tblcustomfields.fieldname = 'turu') THEN tblcustomfields.fieldoptions ELSE NULL END) AS turu
FROM `tblhostingaddons`
LEFT JOIN tbladdons ON tbladdons.id = tblhostingaddons.addonid
LEFT JOIN tblcustomfields ON tblcustomfields.relid = tbladdons.id
WHERE tblhostingaddons.hostingid = '88'
AND tblhostingaddons.status = 'Active'

关于mysql - 如何编辑我的 MySQL 请求最大大小写输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52440459/

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