I am calculating the quantile of the desired record in a table. There are only two columns in the table, X1 <- date, X2 <- price
I use the first select statement to count the number of records less than the one at desired date; the second select statement to count the total record number
Each SELECT statement runs good, but I have trouble to JOIN them together, any hint?
#(
SELECT count(X2) AS rank
FROM EMCDX5y_test
WHERE CONVERT(decimal(8,3), X2) < (SELECT X2 as Current_Level
FROM EMCDX5y_test
WHERE X1 =(SELECT max(X1) from EMCDX5y_test ) )
)
as r
INNER JOIN
(
SELECT count(X2) AS total
FROM EMCDX5y_test
) as t
here is the error message
Server: Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'as'.
Server: Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'as'.