2017-02-11 100 views
0

我想通過分割將sql行分割成多行。 只是假設我有以下記載,SQL: - 將sql行分割成多行

No name date  sub-total tax total 
1 Test 02-11-2017 5000  750 5750 

現在我要像下面的記錄除以3以上子總,稅和總量。

No name date  sub-total tax total 
1 Test 02-11-2017 1666.66 250 1916.66 
1 Test 02-11-2017 1666.66 250 1916.66 
1 Test 02-11-2017 1666.66 250 1916.66 

請建議.. 在此先感謝...

回答

0

您可以使用交叉聯接:

select No, 
    name, 
    date, 
    subtotal/3.0 subtotal, 
    tax/3.0 tax, 
    total/3.0 total 
from your_table t 
cross join (
    select 1 i union all select 2 union all select 3 
    ) x 
+0

非常感謝您@GurV。這按預期工作...... –