我编写了以下SQL查询,效果很好
SELECT
context.data.EventTime as eventTime,
context.device.type as deviceType,
GetRecordPropertyValue(GetArrayElement(context.custom.dimensions, 4), 'MachineName') AS machineName,
GetRecordPropertyValue(GetArrayElement(context.custom.dimensions, 5), 'UserId') AS userId,
GetRecordPropertyValue(GetArrayElement(context.custom.dimensions, 9), 'UserName') AS userName,
GetRecordPropertyValue(GetArrayElement(context.custom.dimensions, 11), 'remoteIpAddress') AS remoteIpAddress,
GetRecordPropertyValue(GetArrayElement(context.custom.dimensions, 13), 'EventName') AS eventName
INTO output1
FROM input1
显示以下结果
有没有办法只返回一个顶级记录,我不想只显示多个记录中的第一个记录
答案 0 :(得分:1)
SELECT TOP 1 W.LineItems_LineItemID, P.CurrentRate, P.CurrentEffectiveDate
FROM WorkOrderLineItems W
JOIN PayScaleLoaclJObCodes P ON P.JobCodeID = W.LineItems_LineItemID
WHERE P.PayScalesLocal_ID = 29 AND W.WorkOrderCurrent_WorkOrderID = 120420
AND P.CurrentEffectiveDate <= '2018-05-27'
ORDER BY P.CurrentEffectiveDate DESC
SELECT TOP子句用于指定要返回的记录数。对于您的情况,您只需要TOP 1
一个。
OR
SELECT W.LineItems_LineItemID, P.CurrentRate, P.CurrentEffectiveDate
FROM WorkOrderLineItems W
JOIN PayScaleLoaclJObCodes P ON P.JobCodeID = W.LineItems_LineItemID
WHERE P.PayScalesLocal_ID = 29 AND W.WorkOrderCurrent_WorkOrderID = 120420
AND P.CurrentEffectiveDate <= '2018-05-27'
ORDER BY P.CurrentEffectiveDate DESC
LIMIT 1