[英]How to create a new table that only keeps rows with more than 5 data records under the same id in Bigquery
[英]KQL :: return only tags with more than 4 records
我創建了一個 Kusto 查詢,允許我返回我們所有的數據庫公園。 查詢只需要10行代碼:
Resources
| join kind=inner (
resourcecontainers
| where type == 'microsoft.resources/subscriptions'
| project subscriptionId, subscriptionName = name)
on subscriptionId
| where subscriptionName in~ ('Subscription1','Subscription2')
| where type =~ 'microsoft.sql/servers/databases'
| where name != 'master'
| project subscriptionName, resourceGroup, name, type, location,sku.tier, properties.requestedServiceObjectiveName, tags.customerCode
根據合同,我們應該只為每個客戶提供 4 個 Azure SQL 數據庫,但有時開發人員會復制一份並將其重命名為_old
或_backup
,突然一個客戶可以擁有 5 或 6 個數據庫。
這增加了雲的總體成本,我想列出擁有 4 個以上數據庫的所有客戶。
為此,我可以使用標簽tags.customerCode
,它具有每個客戶的 3 個字母標識符。
代碼應該像這樣工作:如果一個客戶被稱為 ABC 並且有 4 個 Azure SQL 帶有tags.customerCode
ABC 的數據庫,查詢應該不返回任何內容。 如果有 5 或 6 個數據庫帶有tags.customerCode
ABC,則查詢應返回所有這些數據庫。
不確定 Kusto 是否可以那么靈活。
這是一個可能的解決方案。
需要注意的是,Azure 資源圖只支持有限的 KQL 子集。
resourcecontainers
| where type == 'microsoft.resources/subscriptions'
//and name in~ ('Subscription1','Subscription2')
| project subscriptionId, subscriptionName = name
| join kind=inner
(
resources
| where type =~ 'microsoft.sql/servers/databases'
and name != 'master'
)
on subscriptionId
| project subscriptionId, subscriptionName, resourceGroup, name, type, location
,tier = sku.tier
,requestedServiceObjectiveName = properties.requestedServiceObjectiveName
,customerCode = tostring(tags.customerCode)
| summarize dbs = count(), details = make_list(pack_all()) by customerCode
| where dbs > 4
| mv-expand with_itemindex=db_seq ['details']
| project customerCode
,dbs
,db_seq = db_seq + 1
,subscriptionId = details.subscriptionId
,subscriptionName = details.subscriptionName
,resourceGroup = details.resourceGroup
,name = details.name
,type = details.type
,location = details.location
,tier = details.tier
,requestedServiceObjectiveName = details.requestedServiceObjectiveName
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.