다음을 통해 공유


치트 시트를 Kusto 쿼리 언어 SQL

적용 대상: ✅Microsoft Fabric✅Azure Data ExplorerAzure MonitorMicrosoft Sentinel

SQL에 익숙하고 KQL을 알아보려면 SQL 쿼리 앞에 주석 줄 --과 키워드 explain를 추가하여 SQL 쿼리를 KQL로 변환합니다. 출력은 KQL 구문 및 개념을 이해하는 데 도움이 되는 쿼리의 KQL 버전을 보여 줍니다.

--
explain
SELECT COUNT_BIG(*) as C FROM StormEvents 

출력

쿼리
StormEvents<br>| summarize C=count()<br>| project C

SQL 대 Kusto 참고 자료

다음 표에서는 SQL의 샘플 쿼리와 해당 KQL에 해당하는 쿼리를 보여 줍니다.

범주 SQL 쿼리 Kusto 쿼리 자세한 정보
테이블에서 데이터 선택 SELECT * FROM dependencies dependencies 테이블 형식 식 문
-- SELECT name, resultCode FROM dependencies dependencies | project name, resultCode project
-- SELECT TOP 100 * FROM dependencies dependencies | take 100 take
Null 평가 SELECT * FROM dependencies
WHERE resultCode IS NOT NULL
dependencies
| where isnotnull(resultCode)
isnotnull()
비교 연산자(날짜) SELECT * FROM dependencies
WHERE timestamp > getdate()-1
dependencies
| where timestamp > ago(1d)
ago()
-- SELECT * FROM dependencies
WHERE timestamp BETWEEN ... AND ...
dependencies
| where timestamp between (datetime(2016-10-01) .. datetime(2016-11-01))
between
비교 연산자(문자열) SELECT * FROM dependencies
WHERE type = "Azure blob"
dependencies
| where type == "Azure blob"
논리 연산자
-- -- substring
SELECT * FROM dependencies
WHERE type like "%blob%"
// substring
dependencies
| where type has "blob"
가 있는 경우
-- -- wildcard
SELECT * FROM dependencies
WHERE type like "Azure%"
// wildcard
dependencies
| where type startswith "Azure"
// or
dependencies
| where type matches regex "^Azure.*"
startswith
matches regex
비교(부울) SELECT * FROM dependencies
WHERE !(success)
dependencies
| where success == False
논리 연산자
그룹화, 집계 SELECT name, AVG(duration) FROM dependencies
GROUP BY name
dependencies
| summarize avg(duration) by name
summarize
avg()
Distinct SELECT DISTINCT name, type FROM dependencies dependencies
| summarize by name, type
distinct 요약
-- SELECT name, COUNT(DISTINCT type)
FROM dependencies
GROUP BY name
dependencies
| summarize by name, type | summarize count() by name
// or approximate for large sets
dependencies
| summarize dcount(type) by name
count()
dcount()
열 별칭, 확장 SELECT operationName as Name, AVG(duration) as AvgD FROM dependencies
GROUP BY name
dependencies
| summarize AvgD = avg(duration) by Name=operationName
별칭 문
-- SELECT conference, CONCAT(sessionid, ' ' , session_title) AS session FROM ConferenceSessions ConferenceSessions
| extend session=strcat(sessionid, " ", session_title)
| project conference, session
strcat()
project
순서 지정 SELECT name, timestamp FROM dependencies
ORDER BY timestamp ASC
dependencies
| project name, timestamp
| sort by timestamp asc nulls last
sort
측정값별 상위 n개 SELECT TOP 100 name, COUNT(*) as Count FROM dependencies
GROUP BY name
ORDER BY Count DESC
dependencies
| summarize Count = count() by name
| top 100 by Count desc
top
Union SELECT * FROM dependencies
UNION
SELECT * FROM exceptions
union dependencies, exceptions union
-- SELECT * FROM dependencies
WHERE timestamp > ...
UNION
SELECT * FROM exceptions
WHERE timestamp > ...
dependencies
| where timestamp > ago(1d)
| union
(exceptions
| where timestamp > ago(1d))
참여 SELECT * FROM dependencies
LEFT OUTER JOIN exceptions
ON dependencies.operation_Id = exceptions.operation_Id
dependencies
| join kind = leftouter
(exceptions)
on $left.operation_Id == $right.operation_Id
join
중첩 쿼리 SELECT * FROM dependencies
WHERE resultCode ==
(SELECT TOP 1 resultCode FROM dependencies
WHERE resultId = 7
ORDER BY timestamp DESC)
dependencies
| where resultCode == toscalar(
dependencies
| where resultId == 7
| top 1 by timestamp desc
| project resultCode)
toscalar
Having SELECT COUNT(\*) FROM dependencies
GROUP BY name
HAVING COUNT(\*) > 3
dependencies
| summarize Count = count() by name
| where Count > 3

요약 위치