mysql - 如何编辑我的 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

出现以下结果。但我只希望 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/

相关文章:

mysql - 不同语言的不同 MySQL 表

mysql - 单表和多表语法的区别?

php - MYSQL 将旧列添加为新表中的行

php - 如何将 php 值传递给 javascript 然后传递给 ajax?

PHP:未选择数据库

MySQL 根据字段值忽略(接近)重复项

php - 向从 PHP 中的变量构建的数组添加附加值

Cygwin mysqldump 完整插入

mysql选择两个不同的查询

mysql - CakePHP 中清理 SQL 的所有方法