2014-12-06 69 views
0

我想知道是否可以暫時更改SQL中的數據暫時更改SQL數據

我有三個月爲varchar七月,八月和九月。我想分別將其更改爲1,2,3,這樣我可以做到以下幾點:

SELECT * FROM 
(
(SELECT aID, month AS monthA FROM tblA) AS a 
INNER JOIN 
(SELECT bID, month AS monthB FROM tblB) AS b 
ON a.ID = b.ID 
) 
WHERE a.month < b.month 

我知道這工作

SELECT * FROM 
    (
    (SELECT aID, month AS monthA FROM tblA) AS a 
    INNER JOIN 
    (SELECT bID, month AS monthB FROM tblB) AS b 
    ON a.ID = b.ID 
    ) 
    WHERE (a.month = 'July' AND b.month = 'August') 

回答

0

這聽起來像你只是想剛階段的數據爲1,2,3的數據並不一定在數據庫中更改它是正確的?

爲什麼不做一個案例,將值更改爲1,2,3,然後做你需要的。

SELECT * FROM 
(
(SELECT aID, CASE month WHEN 'July' THEN '1' WHEN 'August' THEN '2' WHEN 'September' THEN '3' ELSE month END AS monthA FROM tblA) AS a 
INNER JOIN 
(SELECT bID, CASE month WHEN 'July' THEN '1' WHEN 'August' THEN '2' WHEN 'September' THEN '3' ELSE month END AS monthB FROM tblB) AS b 
ON a.aID = b.bID 
) 
WHERE a.monthA < b.monthB