MySQL订购问题 - 还有一个问题!

时间:2010-10-11 11:05:24

标签: mysql group-by

好的,请输入以下代码:

SELECT q21 as Comment, q21coding  AS Description 
FROM `tresults_acme` 
WHERE q21 IS NOT NULL AND q21 <> '' 
ORDER BY q21coding = 'Other', q21coding = 'Positive comments', Count ASC

这将带来以下内容(摘录):

Text                                                     Description
Lack of up to date equal pay cases&legislation - t...   Content needs updating
The intranet could contain more "up to date traini...   Content needs updating
Poorly set out. It is hard to find things.             Difficulty in navigating/finding content
Only use the intranet as a necessity. Will ask my ...   Difficulty in navigating/finding content
Never really use it too difficult to be honest, s ...   Difficulty in navigating/finding content

我需要做的是按特定顺序恢复文本,基本上这是描述的COUNT按升序排列 - 有意义吗?

因此,在上面的示例中,“导航/查找内容难度”的文本将首先显示为3,然后“内容需要更新”,因为它的计数为2.

欢迎任何建议!

一如既往地谢谢,

荷马。

2 个答案:

答案 0 :(得分:1)

不完全确定这是否有效(现在无法测试):

SELECT q21 as Comment, q21coding  AS Description, (SELECT COUNT(*) FROM `tresults_acme` as t_a WHERE t_a.q21coding = Description) AS Count 
FROM `tresults_acme` 
WHERE q21 IS NOT NULL AND q21 <> '' 
ORDER BY q21coding = 'Other', q21coding = 'Positive comments', Count ASC

答案 1 :(得分:0)

亲爱的,你不必在order by子句中给出属性的值,这是你在代码中犯的错误。 我不确定,但我认为在选择q21之后,语法的注释类型也需要重新考虑。