一个问题 急啊!!!!

minquan 2003-06-06 11:29:43
有一个问题想请教各位
就是从 表
hm1 hm2 hm3
1 2 3
2 3 4
3 4 5
怎样才能用SQL变成
hm 出现次数
1 1
2 2
3 3
4 2
5 1
我不会啊 会的老兄教我一下
...全文
53 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
nyf1220 2003-06-08
  • 打赏
  • 举报
回复
哎,还在这里说什么啊,人家 zleeway(杂草) 早说对了,按他的方法,我实验过的,绝对正确!
flyfish99 2003-06-08
  • 打赏
  • 举报
回复
哦~我懂了~
他的原理就是把所有的数据都选出来,(形成9个数据的集合),然后在从这9个数据中
实现我们想要的咚咚(group by hm),按值分组~

union的意思就是连接,及把上下两个选择结果组合在一起,如果不加all,默认是distinct的~

爽啊~!
flyfish99 2003-06-08
  • 打赏
  • 举报
回复
怎么我用这段代码
select hm, count(*)
from
(
select hm1 as hm from table1
union all
select hm2 as hm from table1
union all
select hm3 as hm from table1
)
group by hm

出错啊,说groupby有错啊~~~~~~~~~~~~~~~~~~~~~
zjy6631 2003-06-08
  • 打赏
  • 举报
回复
改进耙子的程序
原:
select hm, count(*)
from
(
select hm1 as hm from table1
union
select hm2 as hm from table1
union
select hm3 as hm from table1
)
group by hm


改:

select A.hm, count(A.hm) As Itm
from
(
select hm1 as hm from table1
union all
select hm2 as hm from table1
union all
select hm3 as hm from table1
) A
group by A.hm



一切OK! 耙子提醒提对了.
microjuz 2003-06-08
  • 打赏
  • 举报
回复
union 是什么用的,能不能教教我
nyf1220 2003-06-08
  • 打赏
  • 举报
回复
实验过了,
union all有什么用处啊
可以了,我刚刚弄完,可以出结果了,谢谢了,哈,虽然我不是楼主,
学到了点东西!!
楼住啊,可以结分了!!
zleeway 2003-06-08
  • 打赏
  • 举报
回复
to: pazee(耙子)
union会自动distinct的,要使用union all

select hm, count(*)
from
(
select hm1 as hm from table1
union all
select hm2 as hm from table1
union all
select hm3 as hm from table1
)
group by hm
nyf1220 2003-06-08
  • 打赏
  • 举报
回复
: bbs791109(小别) 的方法好象还行
不过就是要建个表Table_1,里面有个字段hm是不是啊?

bluecyclone 2003-06-08
  • 打赏
  • 举报
回复
学习!
nyf1220 2003-06-08
  • 打赏
  • 举报
回复
to : pazee(耙子) jsyhello(不认输)
我想问下,union是不是有问题啊,当查询出结果的时候,有重复的,系统就会自动合并,所以,统计不出各个值的个数,所以,按你们查询的方法,查出的总是 1,
不知道大家还有什么方法,我也想知道!
minquan 2003-06-08
  • 打赏
  • 举报
回复
用的是delphi 自带的paradox 7.0
蝈蝈太阳 2003-06-07
  • 打赏
  • 举报
回复
高手
智商无下限 2003-06-07
  • 打赏
  • 举报
回复
晚了就蹭分,呵呵!!!!
minquan 2003-06-07
  • 打赏
  • 举报
回复
楼上(耙子)兄的语法应该是对的
可系统回出现 invalid use of keywrod
token: select
line number:3
这是这么回事啊?
hansion3406 2003-06-07
  • 打赏
  • 举报
回复
呵呵..
0000007 2003-06-07
  • 打赏
  • 举报
回复
学习
AaronChengBJ 2003-06-07
  • 打赏
  • 举报
回复
我来借高手的光的
ziqing 2003-06-07
  • 打赏
  • 举报
回复
高手今天都来了!看来问题可以解决了!!
jpyc 2003-06-07
  • 打赏
  • 举报
回复
楼上都是高手
goldencity 2003-06-07
  • 打赏
  • 举报
回复
为什么迟到的总是我啊 !
加载更多回复(9)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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