sql中的排序问题?

78815 2006-02-21 06:32:51
有两个表,
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 ????
这个后面怎么写才能排序?


...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsftest 2006-02-22
  • 打赏
  • 举报
回复
楼主的问题没看明白。。。。请写出希望得到什么样的结果。。。

我也问一个排序问题
table1
col1 col2
1 10
2 7
3 8
4 6
5 长10

col2是varchar类型
如何使col2中数字的可以正常排序啊?
==========================
试试:
select * from testtable order by col2*1

lang11zi 2006-02-22
  • 打赏
  • 举报
回复
我也问一个排序问题
table1
col1 col2
1 10
2 7
3 8
4 6
5 长10

col2是varchar类型
如何使col2中数字的可以正常排序啊?
qybao 2006-02-22
  • 打赏
  • 举报
回复
try

select table1.col2,sum(table2.col2) from table1 left join table2 on table1.col2=table2.col1 group by table1.col2 order by table1.col1
78815 2006-02-22
  • 打赏
  • 举报
回复
不行啊,它说table1.col1不是group的成员,也不是聚合函数
faysky2 2006-02-22
  • 打赏
  • 举报
回复
select table1.col2,sum(table2.col2) as col2 from table1,table2 where table1.col2=table2.col1 group by table1.col2 order by table1.col1
northwolves 2006-02-21
  • 打赏
  • 举报
回复
try:

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

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧