case问题
小弟初学sql。理解能力比较差,在联机丛书里看到了有关case语句的解释,可是怎么也看不懂,于是就想对照着例子理解,可是例子也看不懂。
谁能告诉我下面这句话是什么意思? 谢谢大家了!
USE pubs
GO
SELECT 'Price Category ' =
CASE
WHEN price IS NULL THEN 'Not yet priced '
WHEN price < 10 THEN 'Very Reasonable Title '
WHEN price > = 10 and price < 20 THEN 'Coffee Table Title '
ELSE 'Expensive book! '
END,
CAST(title AS varchar(20)) AS 'Shortened Title '
FROM titles
ORDER BY price
GO
[解决办法]
IS NULL当price 为空是显示为.... 'Not yet priced '
when 条件满足 then 显示结果
[解决办法]
如果price为空就显示Not yet priced
如果price <10就显示Very Reasonable Title
如果price> =10并且 <20就显示Coffee Table Title
如果不符合以上条件就显示Expensive book!
[解决办法]
'Price Category ' 列的值根据Price值显示
'Not yet priced '或者 'Very Reasonable Title '或者 'Coffee Table Title '或者 'Expensive book! '