2017-02-11 99 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。这按预期工作...... –