import psycopg2
import sys
sys.stdout.reconfigure(encoding='utf-8')

dsn = 'postgresql://local-Python:Neo-local-1991125@100.64.0.4:5432/LLZQ-test'
conn = psycopg2.connect(dsn)
cur = conn.cursor()

# 查询 skill_id 和 skill_name 的对应关系及数量
cur.execute("""
    SELECT 
        skill_id, 
        skill_name, 
        COUNT(*) as count
    FROM billiards_dwd.dwd_assistant_service_log
    GROUP BY skill_id, skill_name
    ORDER BY skill_id, count DESC
""")

results = cur.fetchall()

print("| skill_id | skill_name | 记录数 |")
print("|----------|------------|--------|")
for row in results:
    skill_id, skill_name, count = row
    name = skill_name if skill_name else "(NULL)"
    print(f"| {skill_id} | {name} | {count} |")

print(f"\n共 {len(results)} 种组合")

conn.close()
