mysql rename results?
I have this function
SELECT LEFT( eventName, INSTR( CONCAT( eventName, ':' ) , ':' ) ) AS prefix, COUNT( * )
FROM trackingevent
GROUP BY LEFT( eventName, INSTR( CONCAT( eventName, ':' ) , ':' ) )
UNION SELECT homeupload, COUNT( * )
FROM link
GROUP BY homeupload
UNION
SELECT mediaType, COUNT( * )
FROM link
GROUP BY mediaType
UNION
SELECT emailSub, COUNT(*) FR开发者_如何学JAVAOM link WHERE emailSub='1' GROUP BY emailSub
and it generates something like
prefix COUNT(*)
CONTEST_ENTRY: 4
EMAIL_SHARE 77
FLICKR_SHARE 9
SHARE_FACEBOOK 105
SHARE_STATION_LOGIN 223
TWEET_SHARE 18
0 320
1 1
image 320
video 1
1 195
I want to rename the 0,1 and the other 1 to something else. Maybe homeupload, onsite, or something.
The first 0 and 1 are UNION SELECT homeupload, COUNT( * ) FROM link GROUP BY homeupload
As there are two values
The second 1 is UNION SELECT emailSub, COUNT(*) FROM link WHERE emailSub='1' GROUP BY emailSub
How can I rename the results?
in short, using IF
...
UNION
SELECT IF(homeupload = 0,
"someStringDescribingStatus0",
"someStringDescribingStatus1") as homeUploadStatus,
count(*)
FROM ...
精彩评论