【发布时间】:2021-03-27 17:30:34
【问题描述】:
我的表格中的所有数据都是数字格式。例如,
class sex subject medium
5 1 1 1
1 1 1 2
4 3 3 1
5 1 3 2
1 1 3 1
3 1 2 2
1 2 2 2
其他表包含对每个表的每个值的描述。例如,
Table Column value text
Student class 1 1ST
Student class 2 2ND
Student class 3 3RD
Student class 4 4TH
Student class 5 5TH
Student sex 1 male
Student sex 2 female
Student sex 3 creator
Student medium 1 English
Student medium 2 Hindi
我正在尝试提供文本(用户查询时为每列添加标签)。我已经能够为一栏做到这一点。例如,
SELECT class, sex, avg(total_marks) as total
FROM (
SELECT value, text as sex
FROM Label
WHERE table_name = 'Student' and
Column = 'class' or
) AS Label INNER JOIN Student on value = class
GROUP BY class, sex
这会导致
class sex total
1ST 1 64.80
1ST 2 59.66
2ND 1 78.96
2ND 2 96.97
3RD 1 52.67
3RD 2 81.77
4TH 1 61.99
4TH 2 99.78
5TH 1 72.90
5TH 2 70.59
我想展示男性、女性和创造者,而不是性别中的 1 / 2 /3。 Select 和 Group by 列有时可能超过 4 个。我正在使用 MySql 和 PHP Laravel 来执行此操作。
【问题讨论】:
-
您好!你为什么不向我们展示你迄今为止在 Laravel 中所做的事情?