我的select查询中有一个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;
答案 0 :(得分:1)
尝试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;
答案 1 :(得分:0)
请参见以下示例,效果很好
select case
when 400 < 600 then
sec_to_time(400)
else
sec_to_time(300)
end as col
它返回到输出下方
col
00:06:40
因此,如果您的SongLength列的数据类型为数字,那么它应该可以工作