我正在尝试使用连接创建一个选择查询
select distinct code from view req
inner join assoview assreq ON assreq.id_2 = req.id
where req.type_name = 'REQUEST' order by code
仅返回具有
之类关联的代码ABC003
ABC005
但是当我做左联时
select distinct code from view req
left join assoview assreq ON assreq.id_2 = req.id
where req.type_name = 'REQUEST' order by code
我得到了结果
ABC001
ABC002
ABC003
ABC004
ABC005
但我正在寻找如何获得没有像
这样的关联的代码ABC001
ABC002
ABC004
答案 0 :(得分:2)
使用Sub email()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "https://example.com"
logsite = "https://example.com/logoff.do"
With objIE
.Visible = True
.Navigate WebSite
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set unElement = .Document.getElementsByName("username")
unElement.Item(0).Value = "myusername"
Set pwElement = .Document.getElementsByName("password")
pwElement.Item(0).Value = "mypassword"
.Document.forms(0).submit
'.quit
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set expElement = .Document.getElementsByClassName("nav__action dropdown-trigger js--tooltip")
expElement(0).Click
Do While .Busy Or .readyState <> 4
DoEvents
Loop
.Document.getElementById("obb_EXPORT_EXCEL").Click
End With
application.Wait (Now + TimeValue("0:00:02"))
SendKeys "%S", True
application.Wait (Now + TimeValue("0:00:04"))
Const file_PATH As String = "C:\Users\mypc\Downloads\"
Dim file As String
file = Dir$(file_PATH & "BFUK*" & ".xlsx")
application.Wait (Now + TimeValue("0:00:02"))
If (Len(file) > 0) Then
Workbooks.Open(file_PATH & file).Activate
End If
ActiveSheet.Range("A4:BC600").Copy
Windows("macro testing final.xlsm").Activate
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
[L:L].Select
With Selection
.NumberFormat = "General"
.Value = .Value
End With
Range("A3").Select
application.CutCopyMode = False
application.Wait (Now + TimeValue("0:00:20"))
Workbooks(file).Activate
application.Wait (Now + TimeValue("0:00:03"))
ActiveWorkbook.Close savechanges:=False
With New FileSystemObject
If .FileExists(SOME_PATH & file) Then
.DeleteFile SOME_PATH & file
End If
End With
Windows("macro testing final.xlsm").Activate
Worksheets("Pivots").Activate
ThisWorkbook.RefreshAll
application.Wait (Now + TimeValue("0:00:03"))
Worksheets("Email").Activate
application.Wait (Now + TimeValue("0:00:03"))
Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String
Dim r As Range
Set r = Sheets("Email").Range("A1:E72")
r.Copy
EmailSubject = "tNPS Update at " & Format(Time, "hh:mm")
SendTo = Range("Q10")
ccTo = Range("Q10")
Dim outlookApp As Outlook.application
Set outlookApp = CreateObject("outlook.Application")
Dim outMail As Outlook.MailItem
Set outMail = Outlook.CreateItem(olMailItem)
With outMail
.Subject = EmailSubject
.To = SendTo
.CC = ccTo
.body = EmailBody
.display
.send
outMail.display
Dim wordDoc As Word.Document
Set wordDoc = outMail.GetInspector.WordEditor
'Paste as Picture
'wordDoc.Range.PasteAndFormat wdChartPicture
'paste as Table (remove the comma)
wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
End With
Set outlookApp = Nothing
Set outMail = Nothing
Windows("macro testing final.xlsm").Activate
Sheets("Raw").Select
Range("A3:BC900").Select
Selection.ClearContents
Range("A3").Select
End Sub
和<service>
:
left join
您也可以使用where . . . is null
或select distinct code
from view req left join
assoview assreq
on assreq.id_2 = req.id
where req.type_name = 'REQUEST' and
assreq.id_2 is null
order by code;
,但这符合您当前的逻辑。
答案 1 :(得分:0)
一种方法是使用MINUS
运算符:
not in
答案 2 :(得分:0)
只需在IS NULL
表
LEFT JOIN
”即可
SELECT DISTINCT code
FROM view req
LEFT JOIN assoview assreq
ON assreq.id_2 = req.id
WHERE req.type_name = 'REQUEST'
AND assreq.id_2 IS NULL
ORDER BY code
答案 3 :(得分:0)
select distinct code from view req
inner join assoview assreq ON assreq.id_2 <> req.id
where req.type_name = 'REQUEST' order by code