1樓:樂動
mysql> select * from a;
+----+------+------+
| id | b | num |
+----+------+------+
| 1 | b1 | 200 |
| 2 | b1 | 300 |
| 3 | b1 | 400 |
| 4 | b2 | 120 |
| 5 | b2 | 920 |
+----+------+------+
5 rows in set (0.00 sec)mysql> select b,sum(num) from a group by b;
+------+----------+
| b | sum(num) |
+------+----------+
| b1 | 900 |
| b2 | 1040 |
+------+----------+
2 rows in set (0.00 sec)group by b的意思是根據b欄位來分組,後面的sum計算就是根據分組欄位的相同欄位來計算的。
2樓:
!echo"先去重複b的值,然後進臨時表"
select distinct b,num,id from ainto temp b1 with no log;!echo"然後計算出不重複的b,對應的num的總和"
unload to zongshuliang.txtselect sum(num)
from b1
不知道是不是你想要的啊? 或是我把你的問題理解錯了,還有一個可能如下:
select distinct b,sum(num)from a
group by 1
3樓:
select b,sum(num) from (select b,sum(num) from table_name
group by b )
group by b
4樓:匿名使用者
用 distinct
select distinct b,sum(num) from table_name group by b
5樓:匿名使用者
select b, sum(num)
from 表a
group by b
6樓:
select distinct b,sum(num) from table_name
group by b
7樓:匿名使用者
select b,sum(num) from table_name
group by b
8樓:阿基米糊
select b,count(*) from a group by b
9樓:天堂上空的鷹
select b,sum(num) from a group by b
10樓:匿名使用者
select sum(b)
from a
group by b;
sql查詢問題
你這問題好模糊,連表欄位都沒有給出,給你大概寫下,select 訪問人 from 表 where convert varchar 7 日期欄位,120 2014 04 有問題再追問吧 select convert varchar 7 date,23 as date,count from testip...
sql中的查詢問題
select name from user where userid in select id from information where score 60 當選出的id無重複時用這個,如 1,2,3 select name from user where userid in select dis...
SQL關聯查詢問題
select id,date,number,price 所要查詢的資料 from t1 where number in select number number查詢條件,按number分組 from t1 group by number and date in select max date 查詢按...