我是SQL查询的初学者。我需要在表中找到尚未成功的Error1记录。
我的表格如下:
select *
from Table1
where not exists (select success.ImportID, success.LineNumber
from Table1 success
join
(select ImportID, LineNumber
from Table1
where status = 'Error1') overlap on overlap.linenumber = success.LineNumber
and overlap.ImportID = success.ImportID
where success.status = 'success')
此查询不返回包含importId 195和linenumber 7
的行{{1}}
答案 0 :(得分:2)
这是一种更简单的方法, INSERT INTO Specialization ( Specialization_name, Specialization_id, Specialty_id )
VALUES( 'Network technologies','(SELECT Max(Specialization_id) FROM Specialization WHERE Specialty_id = '2')+1', '2');
:
EXCEPT
注意:SELECT ImportID, LineNumber
FROM Table1
WHERE Status = 'Error1'
EXCEPT
SELECT ImportID, LineNumber
FROM Table1
WHERE Status = 'Success'
与EXCEPT
一样,会创建一个不同的结果集。如果您不需要或想要不同的结果,那么UNION
会表现得更好。
答案 1 :(得分:0)
你已经过度复杂了,只需选择那些有错误但不存在相同记录的人
'OPTIONS': {
'ssl': {'ssl-ca': '<PATH TO CA CERT>',
}
}
答案 2 :(得分:0)
我认为这可以满足您的需求:
List<Person> allSearch = dataContext
.User
.Where(n => n.FirstName.Contains(search))
.ToList();
答案 3 :(得分:0)
您可以使用[error1 table]左连接[success table]的简单左连接,并选择[success table]中找不到的记录。检查以下查询。
SELECT E.IMPORTID, E.LINENUMBER, E.STATUS
FROM
(SELECT IMPORTID, LINENUMBER FROM TABLE1 WHERE STATUS = 'Error1') E
LEFT JOIN
(SELECT IMPORTID, LINENUMBER FROM TABLE1 WHERE STATUS = 'Success') S
ON E.IMPORTID = S.IMPORTID AND E.LINENUMBER = S.LINENUMBER
WHERE S.IMPORTID IS NULL AND S.LINENUMBER IS NULL;
答案 4 :(得分:0)
select ImportID, LineNumber
from Table1 t1
where Status in ('Success', 'Error1')
group by ImportID
having max(Status) = 'Error1'