Finally, I've made this shitty sql