settings
我在表中有 order by 设置,我想order by
使用此选项进行更改,在下面的 sql 命令中,如果sortable
字段 intosettings
为 1,则 order by 必须为ORDER BY DATE
,如果sortable
为 2,则 order by 必须为ORDER BY ID
。请帮我有正确的sql命令
MYSQL:
SELECT
SQL_CALC_FOUND_ROWS i.* ,
c.title AS category_name,
u.name,
u.family,
s.title AS status_title,
i.thumb_image,
CONCAT( u.name, ' ', u.family ) AS author
FROM contents i
JOIN categories c ON c.id = i.category
JOIN users u ON u.id = i.posted_by
JOIN status_topics s ON s.id = i.t_status
WHERE
i.portal = 0
AND (CASE WHEN post_type = 4
THEN date(NOW()) BETWEEN i.from_dateTime AND i.to_dateTime
ELSE post_type = 1
END)
(select sortable from settings)
(case when sortable = 1 then
ORDER BY topic_date
case when sortable = 2 then
ORDER BY id
case when sortable = 3 then
ORDER BY public
end)
LIMIT 10