我的数据库中有一个mysql表,如下所示
company_id | bill_month |
134 |Apr
134 |May
134 |Jun
134 |Jul
134 |Aug2k19
134 |Sep2k19
391 |Aug2k19
391 |Sep2k19
现在我想要获取所有公司共有的月份,我想要的结果如下所示
bill_months|
Aug2k19 |
Sep2k19 |
我尝试对以下查询使用自连接
SELECT DISTINCT a.bill_month FROM bf_monthly_bill AS a INNER JOIN bf_monthly_bill AS b
on a.bill_month=b.bill_month WHERE a.company_id IN('134','391')
答案 0 :(得分:2)
您可以按bill_month分组,并在HAVING子句中设置条件:
Dim oneCell as Range
Dim exrcif as String
For each oneCell in Range(“H2:H1000”)
With oneCell
If oneCell.value = 0 Then
exrcif = oneCell.Offset(,-7).Value
Exit For
End If
End With
Next oneCell
Range(“A:H”).AutoFilter Field:=4, , Criteria1:=exrcif
End sub