如果 5 大于 2,我想选择 *,如果为 false,则选择特定列。我哪里错了?
SELECT IF(5>2, *, column_x),
CASE whereheard_name WHEN 'Newspaper' THEN 'a'
WHEN 'TV' THEN 'b'
WHEN 'Internet' THEN 'c'
ELSE '-'
END
AS result
FROM whereheard;
谢谢楼上的回答。这是我正在使用的以下示例存储过程:
DELIMITER $$
USE `registration`$$
DROP PROCEDURE IF EXISTS `test2`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test2`()
BEGIN
IF(5>2) THEN
SELECT * FROM whereheard;
ELSE
SELECT whereheard_name FROM whereheard;
END IF;
END$$
DELIMITER ;
这就是我所说的:
CALL test2(),
CASE whereheard_name WHEN 'Newspaper' THEN 'a'
WHEN 'TV' THEN 'b'
WHEN 'Internet' THEN 'c'
ELSE '-'
END
AS result
FROM whereheard;
我哪里错了?