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

SQL: Right and Left

daco2020 2022. 7. 13. 20:01
반응형

You are given a table named repositories, format as below:

** repositories table schema **

  • project
  • commits
  • contributors
  • address

The table shows project names of major cryptocurrencies, their numbers of commits and contributors and also a random donation address ( not linked in any way :) ).

For each row: Return first x characters of the project name where x = commits. Return last y characters of each address where y = contributors.

Return project and address columns only, as follows:

** output table schema **

  • project
  • address

Case should be maintained.

 

Solution:

SELECT 
  LEFT(project, commits) AS project,
  RIGHT(address, contributors) AS address 
FROM 
  repositories

 

Result:

project address
  ntoLpoh5i
E q6Nnpgg
D  
  5M
Dec MgK
Aete  
I fz2F1
Random 1Kw7VtrVuc2pez8JmePiQmk5fVGFKqBdDK
Random vWR2oU6C56GNtiy
Random vGkxufJcESEyM
Random 15DuV4dzgaeKN88XKYEnu43FcEwRkTWmgZ
Random 14nfG9o8cnUdH7c5W59DvxJhhNN7fwDzyv

 

 

반응형