我对mysql查询有疑问。
我有一张表,下面有数据。
From To Weight
--------------
A B 1
A C 3
B C 2
D E 4
我想得到如下sql结果。。
(?) A B C D E
----------------------
A 0 1 3 0 0
B 0 0 2 0 0
C 0 0 0 0 0
D 0 0 0 0 4
E 0 0 0 0 0
而原始表中的数据是什么并没有确定。我要怎么做?
1条答案
按热度按时间uoifb46i1#
如果知道原始列,可以执行以下操作:
如果不知道原始列,可以将这些值组合成单个字符串:
如果您确实需要单独的列,并且不知道这些值,那么您将需要动态sql。