Query : problem in where section
I need to write a query like this :
SELECT S开发者_运维百科 , D1 , D2 , (D1+D2) as D_Sum , ( (D1+D2) /
(X-(
SELECT SUM(T1+T2)
FROM TBL1
WHERE FCode=81 AND DCode=1 AND S<S
)) AS SSS
FROM TBL1
WHERE Salon=1 AND FCode=81 AND DCode=1
I have problem with S<S
in where section in sub query . S<S
likes FALSE and doesn't works .
First S are all of s in all of records in the table and second S is stored in each record .
S<S
: I need select all records that their s is smaller than the s is stored in the record that now processed .
Give a name to the tables:
SELECT S , D1 , D1 , (D1+D2) as D_Sum , ( (D1+D2) /
(X-(
SELECT SUM(innerTBL.T1+innerTBL.T2)
FROM TBL1 innerTBL
WHERE innerTBL.FCode=81 AND innerTBL.DCode=1 AND outerTBL.S<innerTBL.S
)) AS SSS
FROM TBL1 outerTBL
WHERE Salon=1 AND FCode=81 AND DCode=1
Note: I should use the work "alias" instead of "name".
精彩评论