spend the whole day on this sql and past weeks on this problem to be solved by this sql...