```SQL 国际象棋```
Chess in SQL

原始链接: https://www.dbpro.app/blog/chess-in-pure-sql

本文演示了如何在SQL中构建一个完全可玩、功能齐全的国际象棋棋盘——无需JavaScript或任何框架。核心思想是将8x8棋盘表示为一个表,然后在`SELECT`语句中使用条件聚合将行“透视”为列。这种巧妙的方法将数据转换为可视网格,从而在棋盘上显示棋子。 移动棋子通过简单的`UPDATE`语句实现:从原始位置删除棋子,然后将其插入到新位置。作者通过重现保罗·莫菲和布伦瑞克公爵之间著名的“歌剧棋局”,一步一步地使用纯SQL命令来展示这一点。 该项目突出了SQL超越典型数据存储和检索的惊人表达能力,证明它可以处理像棋盘这样的复杂可视化。这种技术不仅限于国际象棋;它还可以应用于任何基于网格的数据表示,例如日历或热图。

对不起。
相关文章

原文

What if I told you SQL could play chess?

Not "store chess moves in a database." Not "track game state in a table." Actually render a chess board. With pieces. That you can move around. In your browser. Using nothing but SELECT, UPDATE, and a bit of creative thinking.

No JavaScript. No frameworks. Just SQL.

Let's build it.

The Board

First, we need to represent the chess board. A chess board is an 8x8 grid. Each square can either be empty or contain a piece. That's just a table: