如何使用KQL查询同时包含指定多列的所有数据表?
跨表多列条件查询的KQL语句
查找同时包含指定多列的表
要找出同时存在Customer_ID和mail列的所有表,可以利用Kusto的系统表sys.columns实现,它存储了集群中所有表的列元数据。
对应的KQL语句如下:
sys.columns | where name in ("Customer_ID", "mail") | summarize target_column_count = dcount(name) by table_name | where target_column_count == 2 | project table_name
语句逻辑说明
sys.columns:获取所有表的列信息where name in ("Customer_ID", "mail"):筛选出包含目标列的记录summarize target_column_count = dcount(name) by table_name:按表名分组,统计每个表中包含的目标不同列的数量(dcount确保重复列名只计数一次)where target_column_count == 2:仅保留同时包含两个目标列的表project table_name:输出符合条件的表名
扩展:查找包含任意指定列的表
如果需要查询包含Customer_ID或mail中任意一列的表,只需去掉统计数量的过滤条件即可:
sys.columns | where name in ("Customer_ID", "mail") | summarize target_column_count = dcount(name) by table_name | project table_name, target_column_count
内容的提问来源于stack exchange,提问作者Pierrot
相关产品推荐
相关产品推荐

