SQL 是一种用于管理和分析数据的强大语言,但对于初学者来说可能很难学习。这就是 ChatGPT 的用武之地,ChatGPT可以通过可视化SQL查询的关键信息轻松学习SQL。

假设我们想要找出过去一个月内GitHub上最受欢迎的前10个AI项目。以下是执行此操作的SQL查询:

SELECT
  repo_name,
  COUNT(*) AS stars
FROM
  github_events
WHERE
  type = 'WatchEvent'
  AND created_at > DATE_SUB(NOW(), INTERVAL 1 MONTH)
  AND repo_name LIKE '%AI%'
GROUP BY
  repo_name
ORDER BY
  stars DESC
LIMIT
  10

现在,让我们使用 ChatGPT 来 visualize this SQL query using pretty ASCII art diagrams

          +-------------------+            
          | What to Retrieve? |    top 10 
          +-------------------+            
                  | SELECT               
                  | repo_name,           
                  | COUNT(*) AS stars    
                  v                      
          +-------------------+            
          |     From Where?    |    GitHub 
          +-------------------+            
                  | FROM                 
                  | github_events        
                  v                      
          +-------------------+            
          |     Filter By:     |    last month, AI projects, most popular 
          +-------------------+            
                  | WHERE                
                  | type = 'WatchEvent'   
                  | AND created_at > DATE_SUB(NOW(), INTERVAL 1 MONTH) 
                  | AND repo_name LIKE '%AI%' 
                  v                      
          +-------------------+            
          |      Group By      |            
          +-------------------+            
                  | GROUP BY             
                  | repo_name            
                  v                      
          +-------------------+            
          |      Order By      |    most popular 
          +-------------------+            
                  | ORDER BY             
                  | stars DESC           
                  v                      
          +-------------------+            
          |     Limit To 10    |    top 10 
          +-------------------+            
                  | LIMIT                
                  | 10                   
                  v          

此图直观地显示了 SQL 查询的流程,从选择要检索的内容到筛选、分组、排序和限制结果。通过箭头,可以很容易地看到问题中的关键信息与相应的 SQL 语句之间的关系。