MySQL Query Result as a specified string if int equalsHow to output MySQL query results in CSV format?Getting the number of rows with a GROUP BY queryMySQL Query GROUP BY day / month / yearHow do I specify unique constraint for multiple columns in MySQL?How to use count and group by at the same select statementMySQL merging two queries one with group byReference - What does this error mean in PHP?How to count multiple columns in a MySQL queryWrite a SQL query showing total of distinct results of field 'status' filtered per month and yearHow can I use the result of a SQL query in another SQL query

On the meaning of 'anyways' in "What Exactly Is a Quartz Crystal, Anyways?"

Would Taiwan and China's dispute be solved if Taiwan gave up being the Republic of China?

How do pilots align the HUD with their eyeballs?

Why weren't the Death Star plans transmitted electronically?

Subverting the emotional woman and stoic man trope

Why did UK NHS pay for homeopathic treatments?

Lettrine + string manipulation + some fonts = errors and weird issues

Social leper versus social leopard

Building a nine - region cluster chart with Tooltip to display labels associated with 2D points

Can Northern Ireland's border issue be solved by repartition?

Why does this image of Jupiter look so strange?

Is it impolite to ask for an in-flight catalogue with no intention of buying?

Performance for simple code that converts a RGB tuple to hex string

Safe to use 220V electric clothes dryer when building has been bridged down to 110V?

Do wheelchair aircraft exist?

Could Apollo astronauts see city lights from the moon?

A delve into extraordinary chess problems: Selfmate 1

Can a broken/split chain be reassembled?

word frequency from file using partial match

Is it impolite to ask for halal food when traveling to and in Thailand?

Is this Portent-like spell balanced?

Meaning of 'ran' in German?

When is it acceptable to write a bad letter of recommendation?

Draw a horizontal line from the left margin to the end of centered text



MySQL Query Result as a specified string if int equals


How to output MySQL query results in CSV format?Getting the number of rows with a GROUP BY queryMySQL Query GROUP BY day / month / yearHow do I specify unique constraint for multiple columns in MySQL?How to use count and group by at the same select statementMySQL merging two queries one with group byReference - What does this error mean in PHP?How to count multiple columns in a MySQL queryWrite a SQL query showing total of distinct results of field 'status' filtered per month and yearHow can I use the result of a SQL query in another SQL query






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















MySQL



I have the following query



"SELECT Status, COUNT( ticket_id) AS total FROM tickets GROUP BY Status"


Which returns



Status ¦ Total 
0 ¦ 3
2 ¦ 1
3 ¦ 6


Is it possible to change the result to a pharse, for example if



0 = Open, 1 = Hold, 2 = Awaiting End User Response, 3 = Resolved, 4 = Closed.



So then the result of the query would be



Status ¦ Total 
Open ¦ 3
Awaiting end user ¦ 1
Resolved ¦ 6


Any help would be awesome,
Cheers!










share|improve this question



















  • 1





    See dev.mysql.com/doc/refman/8.0/en/…

    – Usagi Miyamoto
    Mar 28 at 17:05

















0















MySQL



I have the following query



"SELECT Status, COUNT( ticket_id) AS total FROM tickets GROUP BY Status"


Which returns



Status ¦ Total 
0 ¦ 3
2 ¦ 1
3 ¦ 6


Is it possible to change the result to a pharse, for example if



0 = Open, 1 = Hold, 2 = Awaiting End User Response, 3 = Resolved, 4 = Closed.



So then the result of the query would be



Status ¦ Total 
Open ¦ 3
Awaiting end user ¦ 1
Resolved ¦ 6


Any help would be awesome,
Cheers!










share|improve this question



















  • 1





    See dev.mysql.com/doc/refman/8.0/en/…

    – Usagi Miyamoto
    Mar 28 at 17:05













0












0








0








MySQL



I have the following query



"SELECT Status, COUNT( ticket_id) AS total FROM tickets GROUP BY Status"


Which returns



Status ¦ Total 
0 ¦ 3
2 ¦ 1
3 ¦ 6


Is it possible to change the result to a pharse, for example if



0 = Open, 1 = Hold, 2 = Awaiting End User Response, 3 = Resolved, 4 = Closed.



So then the result of the query would be



Status ¦ Total 
Open ¦ 3
Awaiting end user ¦ 1
Resolved ¦ 6


Any help would be awesome,
Cheers!










share|improve this question














MySQL



I have the following query



"SELECT Status, COUNT( ticket_id) AS total FROM tickets GROUP BY Status"


Which returns



Status ¦ Total 
0 ¦ 3
2 ¦ 1
3 ¦ 6


Is it possible to change the result to a pharse, for example if



0 = Open, 1 = Hold, 2 = Awaiting End User Response, 3 = Resolved, 4 = Closed.



So then the result of the query would be



Status ¦ Total 
Open ¦ 3
Awaiting end user ¦ 1
Resolved ¦ 6


Any help would be awesome,
Cheers!







mysql sql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 17:01









MarkMark

278 bronze badges




278 bronze badges










  • 1





    See dev.mysql.com/doc/refman/8.0/en/…

    – Usagi Miyamoto
    Mar 28 at 17:05












  • 1





    See dev.mysql.com/doc/refman/8.0/en/…

    – Usagi Miyamoto
    Mar 28 at 17:05







1




1





See dev.mysql.com/doc/refman/8.0/en/…

– Usagi Miyamoto
Mar 28 at 17:05





See dev.mysql.com/doc/refman/8.0/en/…

– Usagi Miyamoto
Mar 28 at 17:05












1 Answer
1






active

oldest

votes


















3
















You need case expression :



select (case (Status) 
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end) as total, count(ticket_id) AS total
from tickets t
group by (case (Status)
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end);





share|improve this answer




















  • 1





    As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

    – Hopper
    Mar 28 at 17:08






  • 1





    @RiggsFolly thank you for your response. I moved my commentary.

    – Hopper
    Mar 28 at 17:11











  • @yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

    – Mark
    Mar 28 at 17:22













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403184%2fmysql-query-result-as-a-specified-string-if-int-equals%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3
















You need case expression :



select (case (Status) 
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end) as total, count(ticket_id) AS total
from tickets t
group by (case (Status)
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end);





share|improve this answer




















  • 1





    As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

    – Hopper
    Mar 28 at 17:08






  • 1





    @RiggsFolly thank you for your response. I moved my commentary.

    – Hopper
    Mar 28 at 17:11











  • @yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

    – Mark
    Mar 28 at 17:22















3
















You need case expression :



select (case (Status) 
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end) as total, count(ticket_id) AS total
from tickets t
group by (case (Status)
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end);





share|improve this answer




















  • 1





    As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

    – Hopper
    Mar 28 at 17:08






  • 1





    @RiggsFolly thank you for your response. I moved my commentary.

    – Hopper
    Mar 28 at 17:11











  • @yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

    – Mark
    Mar 28 at 17:22













3














3










3









You need case expression :



select (case (Status) 
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end) as total, count(ticket_id) AS total
from tickets t
group by (case (Status)
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end);





share|improve this answer













You need case expression :



select (case (Status) 
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end) as total, count(ticket_id) AS total
from tickets t
group by (case (Status)
when 0 then 'Open'
when 1 then 'Hold'
when 2 then 'Awaiting End User Response'
when 3 then 'Resolved'
when 4 then 'Closed'
end);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 17:03









Yogesh SharmaYogesh Sharma

36.9k5 gold badges15 silver badges40 bronze badges




36.9k5 gold badges15 silver badges40 bronze badges










  • 1





    As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

    – Hopper
    Mar 28 at 17:08






  • 1





    @RiggsFolly thank you for your response. I moved my commentary.

    – Hopper
    Mar 28 at 17:11











  • @yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

    – Mark
    Mar 28 at 17:22












  • 1





    As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

    – Hopper
    Mar 28 at 17:08






  • 1





    @RiggsFolly thank you for your response. I moved my commentary.

    – Hopper
    Mar 28 at 17:11











  • @yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

    – Mark
    Mar 28 at 17:22







1




1





As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

– Hopper
Mar 28 at 17:08





As Yogesh stated, you can use a case statement to replace the status integer with the phrase. Alternatively, you could create a table giving the relationship between the code and the description for the status, join to that table, and display the description instead of the code. The code tables ( Status_Code, Status_Description in this case) are really useful for ease of maintenance.

– Hopper
Mar 28 at 17:08




1




1





@RiggsFolly thank you for your response. I moved my commentary.

– Hopper
Mar 28 at 17:11





@RiggsFolly thank you for your response. I moved my commentary.

– Hopper
Mar 28 at 17:11













@yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

– Mark
Mar 28 at 17:22





@yogeshsharma Thanks for your assisstance it is working exactly as I need. Top Man!

– Mark
Mar 28 at 17:22




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403184%2fmysql-query-result-as-a-specified-string-if-int-equals%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript