나는 이렇게 학습한다/Algorithm & SQL

SQL Basics: Maths with String Manipulations

daco2020 2022. 5. 25. 18:03
반응형

Given a demographics table in the following format:

demographics table schema

  • id
  • name
  • birthday
  • race

return a single column named calculation where the value is the bit length of name, added to the number of characters in race.

 

 

Solution:

SELECT 
  BIT_LENGTH(name)+
  CHAR_LENGTH(race) 
  AS calculation 
FROM 
  demographics

'BIT_LENGTH' can obtain the bit length.
'CHAR_LENGTH' or 'LENGTH' can obtain the character length.

 

 

Result:

calculation
81
81
81
61
69
105
81
72
89
...

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Easy SQL: Cube Root and Natural Log  (0) 2022.05.27
Grasshopper - Check for factor  (0) 2022.05.26
SQL Basics: Simple MIN / MAX  (0) 2022.05.24
SQL Basics: Simple JOIN  (0) 2022.05.23
Beginner Series #2 Clock  (0) 2022.05.22