经典SQL题 1/25/50/100美分,多少种可能拼凑成2美元
看到别人写的,自己就分享了一下。结合了自己的看法,讨论一下这个小话题....主要是with关键字
With t1 as( select 200 n union all select n - 25 from t1 where n-25>=0 -- 1 CENT),t2 as( select 200 n union all select n - 25 from t2 where n-25>=0 -- 25 CENT),t3 as( select 200 n union all select n - 50 from t3 where n-50>=0 -- 50 CENT),t4 as( select 200 n union all select n - 100 from t4 where n-100>=0 -- 100 CENT)select t1.n/1 [1美分], t2.n/25 [25美分], t3.n/50 [50美分], t4.n/100 [100美分] from t1,t2,t3,t4 where t1.n + t2.n + t3.n + t4.n = 200order by t1.n descoption(maxrecursion 0)

浙公网安备 33010602011771号