从低到高选择组数据和订单数据

时间:2015-12-02 07:27:45

标签: php mysql sql

表格tbltest中的数据如下所示

    +---------------+--------------+
    | customfieldid | fieldvalue   |
    +---------------+--------------+
    |             1 | 3            |
    |             1 | 7            |
    |             3 | 5            |
    |             3 | 1            |
    |             4 | 5            |
    +---------------+--------------+

我想要customfieldid

fieldvalue asc顺序从此表和分组中选择数据

1 个答案:

答案 0 :(得分:0)

如果您希望按组分列第一个订单: -

Select * From
(SELECT customerfieldid, fieldvalue FROM tbltest
ORDER BY fieldvalue ASC ) new 
GROUP BY new.customefieldid

或者如果您想按顺序排列第一组: -

SELECT `customerfieldid`, `fieldvalue`
FROM `tbltest` 
GROUP BY `customfieldid` 
ORDER BY `fieldvalue` ASC