Re: Question on Adding a New Column in Table
Here you go 'Yu'....try this one
SELECT table2.val,IF(table1.name1=table2.name1,table2.val-table1.val,0) AS result
FROM
(
SELECT @row := @row + 1 AS nomor, tab1.*
FROM
(
SELECT '0' AS name1,0 AS val
UNION
SELECT test_tab.name,test_tab.value
FROM test_tab
UNION
SELECT 'N/A',0
) AS tab1,(SELECT @row := 0) r
) AS table1
LEFT JOIN
(
SELECT @row2 := @row2 + 1 AS nomor, tab1.*
FROM
(
SELECT test_tab.name AS name1,test_tab.value AS val
FROM test_tab
UNION
SELECT 'N/A',0
UNION
SELECT '0' AS NAME,0 AS VALUE
) AS tab1,(SELECT @row2 := 0) r
)AS table2 ON table1.nomor=table2.nomor
pretend that 'test_tab' is your table..
Edited 2 time(s). Last edit at 12/20/2011 04:38AM by Vidy Hermes.
Subject
Written By
Posted
December 10, 2011 04:46AM
Re: Question on Adding a New Column in Table
December 20, 2011 04:26AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.