I have a question about SQL. Here is the case: I have a table with 5 columns (C1...C5) I want to do
select (C1+C2*3-C3*5/C4) from table;
Is there any way of naming the resulting column for referring later in a query ?
Use SQL Server Management Studio In Object Explorer, connect to an instance of Database Engine. In Object Explorer, right-click the table in which you want to rename columns and choose Rename. Type a new column name.
To change a column name, enter the following statement in your MySQL shell: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; Replace table_name , old_column_name , and new_column_name with your table and column names.
SELECT (C1+C2*3-C3*5/C4) AS formula FROM table;
You can give it an alias using AS [alias]
after the formula. If you can use it later depends on where you want to use it. If you want to use it in the where clause, you have to wrap it in an outer select, because the where clause is evaluated before your alias.
SELECT *
FROM (SELECT (C1+C2*3-C3*5/C4) AS formula FROM table) AS t1
WHERE formula > 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With