有两个表,
table1
  col1    col2
  1        a
  2        b
  3         c
  4         d
 ...tabel2
  col1     col2
  a         10
  a          12
  b          7
  b          7
  c        45
 ....
现在先根据table2中的分组统计(要用外连接,将table1中col2中的东西都列出来),然后根据table1中的col1排序
这怎么做啊
select table1.col2,sum(col2) from table1,table2 where table1*=table2 group by table1.col2  ????
这个后面怎么写才能排序?   

解决方案 »

  1.   

    try:select table1.col2 from table1,sum(col2) from table2 where table1.col2 =table2.col1 group by table1.col2  order by table1.col1
      

  2.   

    select table1.col2,sum(table2.col2) as col2 from table1,table2 where table1.col2=table2.col1 group by table1.col2 order by table1.col1
      

  3.   

    不行啊,它说table1.col1不是group的成员,也不是聚合函数
      

  4.   

    tryselect table1.col2,sum(table2.col2) from table1 left join table2 on table1.col2=table2.col1 group by table1.col2 order by table1.col1
      

  5.   

    我也问一个排序问题
    table1
      col1    col2
      1        10
      2        7
      3        8
      4        6
      5        长10col2是varchar类型
    如何使col2中数字的可以正常排序啊?
      

  6.   

    楼主的问题没看明白。请写出希望得到什么样的结果我也问一个排序问题
    table1
      col1    col2
      1        10
      2        7
      3        8
      4        6
      5        长10col2是varchar类型
    如何使col2中数字的可以正常排序啊?
    ==========================
    试试:
    select * from testtable order by col2*1