有2张表
TB_FACTURE表
USER_ID列
TB_MUSIC表
USER_ID列
查询出2张表 USER_ID列中 同一个数据出现了多少遍,主要为了统计 比如:
TB_FACTURE表 TB_MUSIC表
USER_ID列 USER_ID列
数据为: 1 1
2 4
3 5
1 2
2 3
3 4
1 2
2 2
3 4
1 34
2 10
3 23
1
TB_FACTURE表
USER_ID列
TB_MUSIC表
USER_ID列
查询出2张表 USER_ID列中 同一个数据出现了多少遍,主要为了统计 比如:
TB_FACTURE表 TB_MUSIC表
USER_ID列 USER_ID列
数据为: 1 1
2 4
3 5
1 2
2 3
3 4
1 2
2 2
3 4
1 34
2 10
3 23
1
解决方案 »
- 请叫一个sql
- 如果计算几个NLL的列?
- 关于SQL2000性能监视的问题
- 为 爱莫能助的问题 -------- 散分
- 急需一条查询语句~在线等啊~
- 求一个 select 语句
- 下面的sql 如何实现
- 请教关于文本加载
- 帮忙写个查询的SQL语句 谢谢了~ 50分献上
- 为什么我的SQL SERVER 2000服务起来不到,说什么要注册,日志是:SQL Server evaluation period has expired.,怎么办?有朋友说我的是评估版,
- 检查SQL2008DBLock信息,exec sys.sp_dbmmonitorupdate 很多,不理解
- 能否在执行SQL语句(或存储过程时)指定用户身份?
select USER_ID,count(*)
from tb
group by USER_ID
TB_FACTURE表 TB_MUSIC表
USER_ID列 USER_ID列
数据为: 1 1
2 4
3 5
1 2
2 3
3 4
1 2
2 2
3 4
1 34
2 10
3 23
你要的结果是什么?
找不到列 "a" 或用户定义的函数或聚合 "a.count",或者名称不明确
(select count(1) as tb1count from tb1 group by USER_ID) a
full join
(select count(1) as tb2count from tb2 group by USER_ID) b
on a.USER_ID=b.USER_ID
(select USER_ID,count(*) cou1
from TB_FACTURE表
group by USER_ID) a,
(select USER_ID,count(*) cou2
from TB_MUSIC表
group by USER_ID) b
where a.USER_ID=b.USER_ID
比如:(一条语句)
userID showCount
1 13
2 6
4 3
10 1
select user_id,sum(cn)
from(select uesr_id,count(*) as rn from tb1 group by user_id
union all
select uesr_id,count(*) as rn from tb2 group by user_id)t
group by user_id
from(select uesr_id,count(*) as rn from tb1 group by user_id
union all
select uesr_id,count(*) as rn from tb2 group by user_id)t
group by user_id
你写的 跟 教我对的那个 人 就有一个地方不一样
你用的full join
他用的union all这个是什么意思?
Create table #t(userid int)
insert into #tt values(3)
insert into #tt values(3)
insert into #tt values(5)
insert into #t values(3)
insert into #t values(3)
insert into #t values(5)
select * from #tt
select * from #t
select userid,SUM(userid) from (
select * from #tt
union all
select * from #t
) A group by userid
还有
select USER_ID,sum(rn)
from(select USER_ID,count(*) as rn from TB_FACTURE group by USER_ID
union all
select USER_ID,count(*) as rn from TB_MUSIC group by USER_ID)t
group by USER_ID这个语句最后 group by 上面还有一个 小t 这个是干吗的?