雄辩 - 不同的多列但不精确

时间:2016-12-14 13:14:24

标签: mysql laravel-5 eloquent

我的数据库中有以下记录:

[user_id, ip] [1, 127.0.0.1] [NULL, 127.0.0.1]

我希望不同调用的结果返回1行而不是2。

例如,当我希望Model::groupBy('user_id', 'ip')->get()->count();返回2时,1会返回[user_id, ip] [1, 127.0.0.1] [1, NULL],因为ip列中存在重复项。

同样,如果数据是:

Option Explicit Sub Find_Duplicates() Dim col As Integer Dim rng As String col = 3 rng = "A5:A" HighLightDuplicates rng, col ShowMaxOnly rng, col End Sub Sub HighLightDuplicates(ByVal rng As String, ByVal col As Integer) Dim i, j As Integer Dim temp As Variant Range(rng).Select Dim Count As Integer Count = 1 For i = 1 To Selection.Count temp = Range(Left(rng, 1) & i) For j = i + 1 To Selection.Count If temp = Range(Left(rng, 1) & j) And temp <> "" Then Count = Count + 1 'increase the number of duplicates 'highlight the duplicates Range(Left(rng, 1) & i).Interior.Color = RGB(0, 100, 255) Range(Left(rng, 1) & j).Interior.Color = RGB(0, 100, 255) End If Next 'show the number of duplicates If Count > 1 Then Cells(i, col) = Count & " duplicates" End If 'reset count Count = 1 Next End Sub 'show only the biggest number of duplicates in a group Sub ShowMaxOnly(ByVal rng As String, ByVal col As Integer) Dim i, j As Integer Dim temp As Variant Range(rng).Select i = 1 For i = 1 To Selection.Count temp = Range(Left(rng, 1) & i) For j = i + 1 To Selection.Count If temp = Range(Left(rng, 1) & j) And temp <> "" Then Cells(j, col) = "" 'remove the smaller numbers duplicates End If Next Next End Sub

我希望得到同样的结果。

1 个答案:

答案 0 :(得分:0)

如果您觉得合适,可以使用->whereNotNull('user_id')过滤掉这些值。