Is there a way to call and use the newly created column right away when selecting in mssql?

Asked 1 years ago, Updated 1 years ago, 88 views

select T.test_col
        ,MAX(T.test_co) as max_test
        ,max_test as max2 -- I want to use the column information that I calculated earlier like this right away.
from test_table T

Is it completely impossible? Or can I use it through the join door?

sql mssql database

2022-09-20 21:47

1 Answers

You can use WITH section and there are many ways, but if you really want to select the query as you posted, you can just use Subquery.

SELECT
    T_T.test_col,
    T_T.max_test AS max2
FROM (
    SELECT
        T.test_col,
        max(T.text_co) AS max_test
    FROM test_table T
) T_T


2022-09-20 21:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.