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

Register for the Party (SQL for Beginners #3)

daco2020 2022. 6. 5. 08:37

You received an invitation to an amazing party. Now you need to write an insert statement to add yourself to the table of participants.

participants table schema

  • name (string)
  • age (integer)
  • attending (boolean)

NOTES:

  • Since alcohol will be served, you can only attend if you are 21 or older
  • You can't attend if the attending column returns anything but true

NOTE: Your solution should use pure SQL. Ruby is used within the test cases just to validate your answer.

 

 

Solution:

INSERT INTO 
  participants 
VALUES 
  ('Daco', 99, true);

--

SELECT 
  *  
FROM 
  participants;

 

 

Result:

name age attending
Alex 22 true
Sam 24 true
Daco 99 true