我如何在mysql中汇总别名

时间:2016-05-25 10:05:06

标签: mysql

我有一个mysql问题,总结了两列,所以我可以对表进行排序。

cbo = new AjaxControlToolkit.ComboBox();

cbo.ID = string.Format(CultureInfo.GetCultureInfo("fr-FR"), "cbo{0}", RemoveSpecialCharacters(filter.Key)); // filter.key is the name of the combo
            cbo.AutoCompleteMode = AjaxControlToolkit.ComboBoxAutoCompleteMode.SuggestAppend;
            cbo.AutoPostBack = true;
            cbo.Visible = true;
            cbo.MaxLength = 500;

cbo.DataSource = GetFilterData2(requestId, filter.Key); // loads the data source with a list<string>
            cbo.DataBind();
            cbo.ItemInserted += this.CboItemInserted;
            this.cboFilters.Add(cbo);
            li.Controls.Add(cbo); // combo is added to the list item

这个sql运行正常并给我'mycall','a_lake'和'w_lake'但是我需要输出排序('a_lake'+'w_lake')这是总分。

尝试别名和子查询但不起作用或只给出一行作为答案。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

使用:

ORDER BY a_lake + w_lake DESC, `ss_log`.`mycall` DESC

答案 1 :(得分:0)

你能试试吗?

SELECT
*,
a_lake+w_lake AS TotalScore
FROM
(
SELECT distinct mycall, sm, mm, SUM(IF(sm != '', 1,0)) AS 'a_lake', SUM(IF(mm != '', 1,0)) AS 'w_lake' FROM ss_log WHERE conf = '1' GROUP BY mycall 
) AS A
ORDER BY a_lake+w_lake DESC

答案 2 :(得分:0)

尝试使用此查询..

SELECT distinct mycall, sm, mm, SUM(IF(sm != '', 1,0)) + SUM(IF(mm != '', 1,0)) AS 'sum' 
FROM ss_log 
WHERE conf = '1' 
GROUP BY `mycall` 
ORDER BY `ss_log`.`mycall` DESC