来自同一字段的排序值

Ordering values from the same field

我需要帮助:

我有以下 Table.

      P1 P2 P3 P4 P5 P6
John   1  2  3  4  5  7
Paul   2  7  5  1  4  3
Mony   7  6  5  4  3  2

一个名字就是一个已经在网页上注册过的订阅者,所以一个名字就是一个字段。

当订阅者登录后,他必须安排这些变量(P1、P2、P3 等),然后他点击 "save" 按钮,这些值将保存在 mysql table。到这里为止一切正常。

问题是我需要订阅者刷新页面的顺序。我一直在考虑使用 "SELECT FROM ORDER BY" 但这是在您想要订购某些字段时使用的。这里我只有一个字段,我想从中排列这些值。

不知道我解释的好不好。希望如此。

感谢您的帮助。

使用并集规范化数据(逆透视数据)

SELECT Label, P
FROM (Select Name, P1 as P, 'P1' as Label from table union all 
      Select Name, P2 as P, 'P2' as Label from table union all 
      Select Name, P3 as P, 'P3' as Label from table union all 
      Select Name, P4 as P, 'P4' as Label from table union all 
      Select Name, P5 as P, 'P5' as Label from table union all 
      Select name, p6 as P, 'P6' as Label from table ) Z 
WHERE Z.Name = 'Paul' 
ORDER BY P

哪个会给你

P4 1
P1 2
P6 3
P5 4
P3 5
P2 7

然后,如果需要,您可以根据值再次对它进行透视。但是,当您可以在结果集中按名称获取特定字段时,返回的 COLUMNS 的顺序是无关紧要的......所以这真的不是'没有多大意义。

但是所有这些似乎都是徒劳的,因为我认为您正在尝试做的事情更适合 UI 而不是数据库。