当前位置 : 首页 » 互动问答 » 正文

其他列的MySql Group By和Sum总值

分类 : 互动问答 | 发布时间 : 2013-02-24 13:08:21 | 评论 : 4 | 浏览 : 63172 | 喜欢 : 31

我有2列像这样

Image of database

我希望结果是狗6和象2.我到目前为止所做的(和失败的)是这个

SELECT词,SUM(金额)FROM Data Group By '字'

回答(4)

  • 1楼
  • 删除WORD周围的单引号。它会导致列名转换为字符串。

     SELECT word,SUM(amount)
    来自数据
    按字组
  • 2楼
  • 它应该是严重重音 symbol not 单个代码

     SELECT单词,SUM(金额)
    来自数据
    GROUP BY`word`;
    

    Output:

    字SUM(金额)
    狗6
    大象2

    enter image description here

  • 3楼
  • SELECT word,SUM(amount)FROM Data Group By word;
  • 4楼
  • 尝试这种非传统的方法。

     SELECT word,SUM(amount)
    来自数据
    按字组

相关阅读:

MySQL's now() +1 day

MySQL's now() +1 day

How can I tell what edition of SQL Server runs on the machine?

How do I limit the number of rows returned by an Oracle query after ordering?

Oracle SQL: Update a table with data from another table

MySQL date format DD/MM/YYYY select query?

How to insert a value that contains an apostrophe (single quote)?

Count work days between two dates

Multiple select statements in Single query

How to access remote server with local phpMyAdmin client?