我的选择查询中有一个case函数。在这种情况下,我想使用SEC_TO TIME函数将以秒为单位的“ SongLength”转换为mm:ss格式。但是,将函数放在其中时会出现语法错误。

select SongTitle,Artist,SongLength
  case
       when SongLength < 600 then
            sec_to_time(SongLength)
       else
            sec_to_time(SongLength)
  end
 from Songs, Artists where Songs.ArtistId = Artists.Id
order by SongTitle;

最佳答案

尝试SongLength将别名设置为:

select SongTitle,Artist,
(case
when SongLength < 600 then
    sec_to_time(SongLength)
else
    sec_to_time(SongLength)
end) as SongLength
 from Songs join Artists
  on ( Songs.ArtistId = Artists.Id )
 order by SongTitle;

关于mysql - SEC_TO_TIME函数在case函数内中断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52137901/

10-11 00:41