In Time Tec interview question

Logical approach for python and sql