Need to Help query in sql server

It look like a sequel of this, this and this.