Table used
Queryperformedon08/31at9:29pm
SELECTCONCAT(TIMESTAMPDIFF(day,NOME_COLUNA,now()),'dias',MOD(TIMESTAMPDIFF(hour,NOME_COLUNA,now()),24),'hs',MOD(TIMESTAMPDIFF(minute,NOME_COLUNA,now()),60),'min')fromNOME_TABELA
Result
- CONCATfunctiontomergequeryvalues
- TIMESTAMPDIFF-functiontocalculatethedifferencebetweendates
Queryordering
Foralphanumericfields10comesbeforethe2becausetheevaluationisdonefromlefttorightdigittodigit.
Tableused:
Result:
Withnumericvalues,thedefaultorderingisfromlowesttohighest,unlessspecifiedasDESC
inorderby
Tosorttheresult,sinceitisalwaysstartedbyanumber,youcanconverttheresultofthequeryintoanumberthatsqlwillcapturethepartbeforethelettersandconverttoanumber,theresultbythisvalue.
Inquiry:
SELECTCONCAT(TIMESTAMPDIFF(day,NOME_COLUNA,now()),'dias',MOD(TIMESTAMPDIFF(hour,NOME_COLUNA,now()),24),'hs',MOD(TIMESTAMPDIFF(minute,NOME_COLUNA,now()),60),'min')asresultadofromNOME_TABELAORDERBYCAST(resultadoASUNSIGNEDINTEGER)