如何按列,日期对结果集进行分组并限制返回的行数?

时间:2016-04-13 21:13:31

标签: sql group-by sql-order-by

1 个答案:

答案 0 :(得分:1)

SELECT  id_field, fe.*
FROM    User_Field uf
CROSS APPLY
        (
        SELECT  TOP (@limit)
                value, dateUsed
        FROM    Field_E2PValue fe
        JOIN    E2P_Value e
        ON      e.id = fe.id_e2pvalue
        WHERE   id_field = uf.id_field
        ORDER BY
                date_used DESC
        ) fe
WHERE   id_user = @myuser