Oracle SQL:将行数据总和与一列进行比较

时间:2016-04-18 23:44:18

标签: sql oracle sum

我有以下类型的数据,其中interval_mins的总和应该等于特定ID#的Total_mins。我需要Interval_mins缺少行的行,例如对于ID#20。我该怎么做?谢谢,

            foreach (Person p in myPersons)
            {
                command1.Parameters.Clear();
                command1.Parameters.AddWithValue("@PersonalIdentityNumber", string.Format("{0}{1}", p.PersonalIdentityNumber, p.SpecialIdentityNumber));
                command1.Parameters.AddWithValue("@FirstName", p.FirstName);
                command1.Parameters.AddWithValue("@LastName", p.LastName);
                command1.Parameters.AddWithValue("@NationalRegistrationCountyCode", p.NationalRegistrationCountyCode);
                command1.Parameters.AddWithValue("@NationalRegistrationMunicipalityCode", p.NationalRegistrationMunicipalityCode);
                command1.Parameters.AddWithValue("@NationalRegistrationDistributionAddress2", p.NationalRegistrationDistributionAddress2 ?? DBNull.Value.ToString());
                command1.Parameters.AddWithValue("@NationalRegistrationPostCode", p.NationalRegistrationPostCode ?? DBNull.Value.ToString());
                ////command1.Parameters.AddWithValue("@NationalRegistrationCity", postOrt);
                ////command1.Parameters.AddWithValue("@BirthCountyCode", fodelselanKod);
                ////command1.Parameters.AddWithValue("@BirthParish", fodelseforsamling);
                command1.Parameters.AddWithValue("@CitizenshipCode", p.CitizenshipCode);
                //// command1.Parameters.AddWithValue("@CitizenshipDate", medborgarskapsdatum);
                command1.Parameters.AddWithValue("@LastChangedDate", datum);



                command1.ExecuteNonQuery();

                Console.WriteLine(p.PersonalIdentityNumber);


            }

1 个答案:

答案 0 :(得分:3)

如果您只是在寻找ID,则总数不匹配:

select id
from t
group by id
having max(total_mins) <> sum(interval_mins);