144k views
0 votes
Write a SELECT statement that returns these four columns from the Products table: The list_price column A column that uses the FORMAT function to return the list_price column with 1 digit to the right of the decimal point A column that uses the CONVERT function to return the list_price column as an integer A column that uses the CAST function to return the list_price column as an integer Use column aliases for all columns that contain a function.

1 Answer

8 votes

Answer:

See explanation below

Step-by-step explanation:

SELECT list_price,

FORMAT(list_price, 1) AS formatted_list_price,

CONVERT(INT, list_price) AS converted_list_price,

CAST (list_price AS INT) AS casted_list_price

FROM products_table;

In SQL, the SELECT statement is used to initiate a query. It lists the variables that will be contained in the output, just like choosing items on a list, with each item being separated by a comma.

The FORMAT, CONVERT, CAST are all functions that are used to change the format of a value. Their formats are;

  • FORMAT - Format (value, decimal places)
  • CONVERT - Convert (datatype, value)
  • CAST - Cast ( value AS datatype

In SQL, aliases are used to rename variables (usually those that contain functions) to ones taste. The AS is used after the function and the new name follows right after.

User Marek Dzikiewicz
by
5.0k points