我有以下MySQL表:如何在單個語句中的SQL中執行此操作?
+---------+------------+------+--------+------+---------+------------+-------+---------+----------+------------+------------+ | Version | Yr_Varient | FY | Period | CoA | Company | Item | Mvt | Ptnr_Co | Investee | GC | LC | +---------+------------+------+--------+------+---------+------------+-------+---------+----------+------------+------------+ | 201 | 1 | 2010 | 1 | 11 | 23 | 1110105000 | 60200 | | | 450000 | 450000 | | 201 | 1 | 2010 | 1 | 11 | 23 | 2110300000 | 60200 | | | -520000 | -520000 | | 201 | 1 | 2010 | 1 | 11 | 23 | 1220221600 | | | | 78080 | 78080 | | 201 | 1 | 2010 | 1 | 11 | 23 | 2130323000 | | | | 50000 | 50000 | | 201 | 1 | 2010 | 1 | 11 | 23 | 2130322000 | | | | -58080 | -58080 | | 201 | 1 | 2010 | 1 | 11 | 23 | 3100505000 | | | | -275000 | -275000 | | 201 | 1 | 2010 | 1 | 11 | 23 | 3200652500 | | | | 216920 | 216920 | | 201 | 1 | 2010 | 1 | 11 | 23 | 3900000000 | | | | 58080 | 58080 | | 201 | 1 | 2010 | 1 | 11 | 26 | 1110105000 | 60200 | | | 376000 | 376000 | | 201 | 1 | 2010 | 1 | 11 | 26 | 2110300000 | 60200 | | | -545000 | -545000 | | 201 | 1 | 2010 | 1 | 11 | 26 | 1220221600 | | | | 452250 | 452250 | | 201 | 1 | 2010 | 1 | 11 | 26 | 2130323000 | | | | -165000 | -165000 | | 201 | 1 | 2010 | 1 | 11 | 26 | 2130322000 | | | | -118250 | -118250 | | 201 | 1 | 2010 | 1 | 11 | 26 | 3100505000 | | | | -937750 | -937750 | | 201 | 1 | 2010 | 1 | 11 | 26 | 3200652500 | | | | 819500 | 819500 | | 201 | 1 | 2010 | 1 | 11 | 26 | 3900000000 | | | | 118250 | 118250 | | 201 | 1 | 2010 | 1 | 11 | 37 | 1110105000 | 60200 | | | 777000 | 777000 | | 201 | 1 | 2010 | 1 | 11 | 37 | 2110308000 | 60200 | 43 | | -255000 | -255000 | | 201 | 1 | 2010 | 1 | 11 | 37 | 2130321500 | | | | 180000 | 180000 | | 201 | 1 | 2010 | 1 | 11 | 37 | 2130322000 | | | | -77000 | -77000 | | 201 | 1 | 2010 | 1 | 11 | 37 | 2310407001 | | 1 | | -625000 | -625000 | | 201 | 1 | 2010 | 1 | 11 | 37 | 3100505000 | | | | -2502500 | -2502500 | | 201 | 1 | 2010 | 1 | 11 | 37 | 3200652500 | | | | 2425500 | 2425500 | | 201 | 1 | 2010 | 1 | 11 | 37 | 3900000000 | | | | 77000 | 77000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1110105000 | 60200 | | | 2600000 | 2600000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1140161000 | 60200 | | 23 | 430000 | 430000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1140161000 | 60200 | | 26 | 505556 | 505556 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1140160000 | 60200 | 37 | | 255000 | 255000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1160163000 | 60200 | 99999 | 48 | 49428895 | 49428895 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1160163000 | 60200 | 99999 | 49 | 188260175 | 188260175 | | 201 | 1 | 2010 | 1 | 11 | 43 | 2310405500 | | | | -237689070 | -237689070 | | 201 | 1 | 2010 | 1 | 11 | 43 | 2110300000 | 60200 | | | -1000 | -1000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 2110300500 | 60200 | | | -3999000 | -3999000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 1220221600 | | | | 1571112 | 1571112 | | 201 | 1 | 2010 | 1 | 11 | 43 | 2130321500 | | | | -805556 | -805556 | | 201 | 1 | 2010 | 1 | 11 | 43 | 2130322000 | | | | -556112 | -556112 | | 201 | 1 | 2010 | 1 | 11 | 43 | 3100505000 | | | | -836000 | -836000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 3200652500 | | | | 781000 | 781000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 3300715700 | | 99999 | 32 | -440000 | -440000 | | 201 | 1 | 2010 | 1 | 11 | 43 | 3300715700 | | 99999 | 26 | -61112 | -61112 | | 201 | 1 | 2010 | 1 | 11 | 43 | 3900000000 | | | | 556112 | 556112 | +---------+------------+------+--------+------+---------+------------+-------+---------+----------+------------+------------+
我需要把所有的行與MVT = 60200和1.1乘以該行中的每一個GC和LC記錄,並添加包含變化的新行回相同表將FY設置爲2011.
如何在1條語句中完成所有這些操作?
是否有可能在1條語句中完成所有這些(我對SQL知之甚少)?
這是否可以在標準SQL中完成,因爲數據庫將移植到另一個數據庫服務器?
我不知道它是哪個服務器。
您是否需要替換現有的行或添加新行? – Anna 2009-11-11 06:54:21
我需要添加新行。 – Kryten 2009-11-11 06:56:40