MulaiMulai sekarang secara gratis

Type CASTs

In the video, you saw that type casts are a possible solution for data type issues. If you know that a certain column stores numbers as text, you can cast the column to a numeric form, i.e. to integer.

SELECT CAST(some_column AS integer)
FROM table;

Now, the some_column column is temporarily represented as integer instead of text, meaning that you can perform numeric calculations on the column.

Latihan ini adalah bagian dari kursus

Introduction to Relational Databases in SQL

Lihat Kursus

Petunjuk latihan

  • Execute the given sample code.
  • As it doesn't work, add an integer type cast at the right place and execute it again.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

-- Calculate the net amount as amount + fee
SELECT transaction_date, amount + fee AS net_amount 
FROM transactions;
Edit dan Jalankan Kode