如何返回多列的最小值并返回其标题?

时间:2016-10-03 09:08:30

标签: sql phpmyadmin

例如,我有表:

Name Week 8am-9am 9am-10am 10am-11am

C1   1    27%     32%      11%
C1   2    4%      29%      95%
C2   3    9%      44%      57%

我希望返回最小值以及特定名称的周和时间范围,例如名称C1:

Name Week 8am-9am
C1   2    4%

2 个答案:

答案 0 :(得分:0)

检查类似的东西:

select name, week, 8am-9am from table t1
where 8am-9am in (selec min(8am-9am) from table t2 group by name having t2.name=t1.name)

答案 1 :(得分:0)

由于您的表格设计并不完美,我从一个派生表开始,将Starting check in English (American)... 1. Line 1, column 19 Message: Possible spelling mistake found (deactivate) Correction: in; win; bin; pin; tin; min; Lin; din; gin; kin; yin; ain; fin; sin; IN; In; Min; PIN Context: I.- Any reference _in this Section to a panicular genus or sp... 2. Line 1, column 41 Message: Possible spelling mistake found (deactivate) Correction: particular; funicular Context: ...I.- Any reference _in this Section to a panicular genus or species of an anirmgl, cxccpl ... 3. Line 1, column 74 Message: Possible spelling mistake found (deactivate) Correction: animal Context: ...n to a panicular genus or species of an anirmgl, cxccpl where the context 4. Line 1, column 83 Message: Possible spelling mistake found (deactivate) Context: ...nicular genus or species of an anirmgl, cxccpl where the context Potential problems found: 4 (time: 171ms) How you can improve LanguageTool 不同的列合并为一个。

UNION ALL