You could have just said all that in your original post and save my and (everyone else who spent some thought into it)'s time.
As John said, this is not a HANA specific question but rather a SQL question.
StackOverflow is a good starting point, but it brings to me the realization that we do not have a proper place within SCN to ask SQL questions. We have for ABAP & Java, might be time for us to have a space for SQL & JavaScript as well.