有3个表a,b,c有共同的2个项ID,P,都不是主键1,希望查询各个ID在三个表内P值=2的总记录数
2,得出的结果如何分ID储存在表D里?
表D结构:
ID P
值 01 4
02 3
2,得出的结果如何分ID储存在表D里?
表D结构:
ID P
值 01 4
02 3
解决方案 »
- 如站长统计这种功能,在任何网站只要插入一段js代码的引用就可以调用,是什么
- 关于GridView绑定XML数据源,请高手指点,多谢。
- Redirect 到另一个网站,怎么保持cookie?
- 是在郁闷证则表达高手帮写个者则表达式取值的问题谢谢阿现在没分了以后给阿
- gridview 插入记录有问题 “未将对象引用设置到对象的实例”
- 请问框架窗体间的通讯怎么实现?
- 怎么样连接一个远方的Access数据库?
- 怎么在SQL Server2005里查看所有字段的“类型” “是否为空” “默认值”这些。。。
- 了解WINDOWS验证的请进来(一个我百思不得其解的问题)
- asp.net中怎样做跳转菜单
- 建立网站请教问题?
- .net 环境下的asp.net web Application 编译后的Debug 与 Release版本有什么区别?
实在不明白
select count(*) as Total from
(select count(ID) from a where p = 2
union
select count(ID) from b where p = 2
union
select count(ID) from c where p = 2)
是这样吗?楼主
比如a中
ID P
1 2
2 1
3 2b中
ID P
1 1
2 2
3 1C中
ID P
1 2
2 2
3 2
要得出如下结果在D内
ID SUM
1 2
2 2
3 1
(select count(ID) ,min(Id) as XID from a where p = 2
union
select count(ID),min(Id) as XID from b where p = 2
union
select count(ID),min(Id) as XID from c where p = 2)
group XID可能不行,自己再改改,就是这个思路
(
select * from a
union all
select * from b
union all
select * from c
)g where p=2 group by id
(
select * from a
union all
select * from b
union all
select * from c
)g where p=2 group by id按照你上面的例子得出的结果应该是
ID SUM
1 2
2 2
3 2
(
select * from a
union all
select * from b
union all
select * from c
)g where p=2 group by id试了,很对
包含 UNION 运算符的查询表达式中的所有查询都必须在选择列表中包含同样数目的表达式。
(
select P from a
union all
select P from b
union all
select P from c
) where p=2 group by id
在关键字 'where' 附近有语法错误。
包含 UNION 运算符的查询表达式中的所有查询都必须在选择列表中包含同样数目的表达式。
(
select id,p from a
union all
select id,p from b
union all
select id,p from c
)g where p=2 group by id那就这样写咧,列出字段名
g 是别名,随便你怎么写都行
拜托,多动点脑筋行不行。