如何重命名该值?它给了我IN()子句中最后选择的值。
SELECT cf_1573, SUM(counter) AS lyncs
FROM (
SELECT
cf_1573,
COUNT(cf_1573) AS counter
FROM vtiger_purchaseordercf
WHERE cf_1573
IN('Lync Front End (Std)','Lync Front End (Ent)','Lync Backend',
'Lync Edge','Lync SBA','Lync DNS Checks','Lync Certificate Checks')
GROUP BY cf_1573
) AS mslync
我有这个输出:
cf_1573 |lyncs
Lync Certificate Checks | 8
sub-query
给了我这个:
cf_1573 | counter
Lync Certificate Checks | 1
Lync DNS Check | 3
Lync Edge | 1
Lync SBA | 3
我希望输出显示“Data Lync”而不是“Lync Certificate Checks”,这是我IN() clause
中的最后一个值。谢谢你的帮助。
答案 0 :(得分:1)
尝试以下查询。
SELECT 'Data Lync' as `cf_1573`, SUM(counter) AS lyncs
FROM (
SELECT
cf_1573,
COUNT(cf_1573) AS counter
FROM vtiger_purchaseordercf
WHERE cf_1573
IN('Lync Front End (Std)','Lync Front End (Ent)','Lync Backend',
'Lync Edge','Lync SBA','Lync DNS Checks','Lync Certificate Checks')
GROUP BY cf_1573
) AS mslync
答案 1 :(得分:0)
您可以在适用时使用CASE
SELECT
cf_1573 = CASE
WHEN cf_1573 = 'Lync Certificate Checks' THEN 'Data Lync'
ELSE cf_1573
END ,
SUM(counter) AS lyncs
FROM
( SELECT
cf_1573,
COUNT(cf_1573) AS counter
FROM vtiger_purchaseordercf
WHERE cf_1573 IN ('Lync Front End (Std)','Lync Front End (Ent)',
'Lync Backend','Lync Edge','Lync SBA','Lync DNS Checks',
'Lync Certificate Checks')GROUP BY cf_1573) AS mslync
)
)table_A