好的,我有超过一百万条记录,我需要从数据库中选择列数大于或等于 10 的所有信息。
我知道使用必须使用 group by 并使用 where 我不能使用聚合函数和运算符,所以我想要的伪代码是
Select column1,column2,column3
From MYdatabase
Where count(column1) > 10
这就是我卡住的地方。我是否使用子查询并添加一个名为 count 的列?我不确定我将如何编写代码,而且我是一个初级 SQL 用户,我可能正在寻找完全错误的方向。
我的整个查询如下,我想修改如果只有计数(callid)> = 10 的记录将被选中。
Select
FiscalMonthYear,
'MyCenter' = Case EP.Center
When 'Livermore Call Center' Then 'LCC'
When 'Natomas Call Center' Then 'NCC'
When 'Concord Call Center' Then 'CCC'
When 'Virtual Call Center' Then 'VCC'
When 'Morgan Hill Call Center' Then 'MHCC'
Else Center
End,
ECH.segstart,
ECH.consulttime,
EP.Queue,
(EP.MgrFName +' '+ EP.MgrLName)AS Manager,
(EP.SupFName +' '+ EP.SupLName)AS Supervisor,
(EP.RepFName +' '+ EP.RepLName)As Agent,
EP.RepPERNR,
LEFT(ECH.segstart, 19) as SegmentDateTime,
ECH.origlogin,
ECH.dialed_num,
ECH.segment,
ECH.SegStart_Date,
ECH.callid
FROM CMS_ECH.dbo.CaliforniaECH ECH
INNER JOIN CAPLESQL02.InfoQuest.dbo.IQ_Employee_Avaya_Id A ON ECH.origlogin = A.AvayaID
AND getdate () BETWEEN StartDate AND EndDate
INNER JOIN CAPLESQL02.InfoQuest.dbo.IQ_Employee_Profiles_v3 EP ON A.IQID = EP.RepID
AND getdate () BETWEEN RepToSup_StartDate and RepToSup_EndDate
AND getdate () BETWEEN SupToMgr_StartDate and SupToMgr_EndDate
AND getdate () BETWEEN RepQueue_StartDate and RepQueue_EndDate
INNER JOIN Cal_RemReporting.dbo.udFiscalMonthTable f on ECH.SegStart_Date = f.Tdate
Where dialed_num not like '______'
AND dialed_num not like ''
AND dialed_num not like '_______'
and EP.Center is NOT Null
and EP.Center not like 'Comm Ops'
and EP.Center not like 'Same Day Group'
and MgrLName not like 'Hollman'
and consulttime > 0
and ECH.SegStart_Date between getdate()-90 and getdate()-1
and EP.Queue not IN ('BST','Collections', 'DST','DSR','Escalations','Cable Store')
我自己解决了这个问题,方法是使用内部连接一个查询,该查询选择前 10 个并连接 dialed_num 列上的所有数据。完美运行,谢谢大家的帮助!