sql reWritten