试图弄清楚为什么这不起作用
答案 0 :(得分:3)
由于在解码语句中使用<
>
=
而导致问题,请改用:
SELECT a.account_id "Account ID",
a.first_name ||' '|| a.last_name "Name",
b.date_and_time_created "Date Created",
c.date_and_time_ordered "Date Ordered",
c.date_and_time_ordered - b.date_and_time_created "Days Ordered After Created",
(case when ( c.date_and_time_ordered - b.date_and_time_created < 5 ) then 'No Reminder Needed'
when ( c.date_and_time_ordered - b.date_and_time_created >= 5 ) then 'Reminder Needed'
else ' '
end ) "Reminder"
FROM shopper a
JOIN shopping_cart b ON a.account_id = b.shopper_account_id
JOIN orders c ON a.account_id = c.shopper_account_id
答案 1 :(得分:1)
或者,如果你坚持使用DECODE(但是,我不知道你为什么要这样做,因为CASE在这里更合适),你可以使用SIGN功能,例如
SELECT DECODE (
SIGN ( (c.date_and_time_ordered - b.date_and_time_created) - 5),
-1, 'less than 5',
'greater than or equal to 5')
result
FROM ...