sql语句:group by 子句
group by 子句 按组统计数据。
例子:

  1. select orderid,sum(ordernum) as num  from order group by orderid
  2. //查找order表内orderid值不重复的记录,把ordernum和的值赋于别名num
  3. select orderid,ordernum from order group by orderid
  4. //这种写法是错误。因为没有用到函数。sum() avg()等

上面那句没用到函数产生错误的原因。现在Cngothic剖析一下
group by 子句 按组统计数据.意思
orderid ordernum
1 2
1 3
2 1
2 1
Read the rest of this entry »

,