Refinement of manual SQL