如何编辑MySQL请求的最大用例输出

如何编辑MySQL请求的最大用例输出

当我运行以下查询时。

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

结果如下。但我只想把字体排成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/

10-15 10:53