存储过程中的条件间隔

conditional interval in stored procedure

我想根据存储过程中的参数更改此 SQL 语句中的间隔。我想使用三个不同的时间间隔:1 天、8 小时、1 小时

CREATE DEFINER= 'dbshizzle' PROCEDURE `getData`(in sD text(17), in sT text(8))
BEGIN
select stime, sval
from tblNumber
where sDix = 'allright'
and timestamp >= now() - interval 1 day
order by timestamp;
END

我应该使用带有整数参数还是文本参数的 IF 语句?

只调整参数并将值作为小时传递怎么样?

CREATE DEFINER = 'dbshizzle' PROCEDURE `getData`(
    in in_sD text(17),  -- should change to varchar
    in in_sT text(8),   -- should change to varchar
    in in_hours int
)
BEGIN
    select stime, sval
    from tblNumber
    where sDix = 'allright'
    and timestamp >= now() - interval in_hours hour
    order by timestamp;
END;