我有一个问题,我需要使用连接显示一些数据。其中一列必须按“颜色”和流行度进行分组(因此最常出现的颜色组将显示为第一组行等等。)
到目前为止,我已经进行了连接,并设法按颜色对其进行分组:
Sub test()
Dim outlookapp As Object
Dim olNs As Outlook.Namespace
Dim myFldr As Outlook.Folder
Dim objMail As Object
Dim myTasks As Outlook.Items
Dim daysAgo As Long
Dim projIDsearch As String
Dim myRecipient As Outlook.Recipient
Set outlookapp = CreateObject("Outlook.Application")
Set olNs = outlookapp.GetNamespace("MAPI")
Set myRecipient = olNs.CreateRecipient("SharedMailboxName")
myRecipient.Resolve
Set myFldr = olNs.GetSharedDefaultFolder(myRecipient, olFolderInbox)
projIDsearch = ActiveCell.Cells(1, 4)
' Restrict search to daysAgo
daysAgo = 3
Set myTasks = myFldr.Items.Restrict("[ReceivedTime]>'" & Format(Date - daysAgo, "DDDDD HH:NN") & "'")
For Each objMail In myTasks
If (InStr(1, objMail.Subject, projIDsearch, vbTextCompare) > 0) Then
objMail.Display
End If
Next
End Sub
我只需要按受欢迎程度组织相同的颜色列,是否有一种简单的方法可以做到这一点?
提前致谢
答案 0 :(得分:1)
也许:
ORDER BY COUNT(*) OVER (PARTITION BY colour) DESC, colour
这将为您提供结果,首先是最流行的颜色。如果您有两种具有相同流行度的颜色,那么您可以按颜色分类。
答案 1 :(得分:1)
如果我理解正确的问题,我会尝试类似的事情:
SELECT C.colour, T1.F1, T1.F2, T2.F3, T2.F4
FROM (
SELECT colour, COUNT(*) as Popularity FROM tblexampl1
GROUP BY colour) C
JOIN tblexampl1 T1 ON C.colour = T1.colour
JOIN tblexampl2 T2 on T1.unique_id = T2.unique_id
ORDER BY C.Popularity DESC
如果Oracle支持WITH,您可以将子查询放在一个更易于阅读的WITH子句中。