我正在尝试存储 EAV 表,但无法正常工作。我得到了结果,但我无法对其进行排序。
这是我的查询:
SELECT
formFields.uid,
formFields.formId,
formFields.postId,
formFields.name,
formFields.value
FROM formFields
INNER JOIN formFields aux
ON (aux.name = "date")
WHERE
formFields.formId = "1789"
AND formFields.deleted = 0
AND formFields.hidden = 0
ORDER BY aux.value DESC
这是表格:
uid formId postId name value
1 1789 1 title example title #1
2 1789 1 date 1341091600
3 1789 2 title example title #2
4 1789 2 date 1341092300
5 1789 3 title example title #3
6 1789 3 date 1341081200
这是我需要的结果:
uid formId postId name value
3 1789 2 title example title #2
4 1789 2 date 1341092300
1 1789 1 title example title #1
2 1789 1 date 1341091600
5 1789 3 title example title #3
6 1789 3 date 1341081200
结果按名称列中具有日期的值排序
(这些值只是示例)
编辑:这是一个 sqlfiddle:http ://sqlfiddle.com/#!2/0d3c32/2