进行数据库测试时需要根据不同场景查询数据,以便验证发现的问题是否为脏数据引起的。记录一下最近常用的查询方法:
1. 查询表中重复数据(id不同,多个字段值相同)
select P1.* from project as P1, project as P2where P1.id<>P2.id and P1.ProjectId=P2.ProjectId and P1.ServiceTypeId=P2.ServiceTypeId and P1.Rank=P2.Rank
2.连接多个表数据
select Name, FirstName, LastName, HoursWorkedfrom employee as E, project as P, assignment as Awhere E.EmployeeNumber=A.EmployeeNumber and P.projectID=A.ProjectIDorder by P.ProjectID, A.EmployeeNumber
或:
select Name, FirstName, LastName, HoursWorkedfrom employee as E join assignment as A on E.EmployeeNumber=A.EmployeeNumber join project as P on P.projectID=A.ProjectIDorder by P.ProjectID, A.EmployeeNumber