-2

我需要你的帮助!

我的数据库上有这个。

table name: tblClient

-------------------------------------------------
id        | stars1       | stars2      | stars3 |
-------------------------------------------------
1         | 5            | 0           | 0      |
2         | 4            | 0           | 0      |
3         | 0            | 5           | 0      |
4         | 0            | 4           | 0      |
5         | 0            | 0           | 5      |
-------------------------------------------------

产生此输出的 SQL 语句是什么?

-------------------------------------------------
id        | stars1       | stars2      | stars3 |
-------------------------------------------------
1         | 5            | 0           | 0      |
3         | 0            | 5           | 0      |
5         | 0            | 0           | 5      |
2         | 4            | 0           | 0      |
4         | 0            | 4           | 0      |
-------------------------------------------------

我已经这样做了,SELECT * FROM tblClient ORDER BY stars1 DESC,stars2 DESC,stars3 DESC,id ASC但似乎输出错误。

任何帮助,将不胜感激 :)

4

4 回答 4

2

这是查询:

SELECT id,stars1, stars2 ,stars3
FROM(
  SELECT id,stars1, stars2 ,stars3, (stars1+stars2+stars3) as sum 
  FROM tblClient 
  GROUP by id
  ORDER BY sum desc) as sorted;

我为你做了一个小提琴,在这里查看http://sqlfiddle.com/#!2/dd5d3/10

于 2013-09-20T08:06:57.997 回答
0

试试这个

SELECT * FROM tblClient ORDER BY stars1 desc,stars2 desc,stars3 desc,id desc;
于 2013-09-20T07:58:32.193 回答
0

SELECT * FROM tblCleint ORDER BY stars1+stars2+stars3 desc;

这是您的查询的解决方案...

于 2013-09-20T08:11:45.890 回答
0
SELECT 
  * 
FROM 
  tblClients 
ORDER BY 
  stars1*1.1+stars2*1.05+stars3 DESC
于 2013-09-20T08:38:30.007 回答