哪位高手能帮我看下这条sql语句的问题,为什么查询结果只能显示一列(即bjdj01)?select count(*) as bjdj01 from sb_ztb where sjdxzt='1'
union
select count(*) as bjdj02 from sb_ztb where sjdxzt='2'
union
select count(*) as bjdj03 from sb_ztb where sjdxzt='3'
union
select count(*) as bjdj02 from sb_ztb where sjdxzt='2'
union
select count(*) as bjdj03 from sb_ztb where sjdxzt='3'
解决方案 »
- 设计关系数据库模式
- 触发器问题
- 求教一个sql
- All schedulers on Node 0 appear deadlocked due to a large number of worker threa
- 创建用户的时候就指定了他的数据库角色,但在设置用户属性时会出现一个对话框来设置用户对库中每个表的权限,这是不是进一步细划了用户的
- 我下的软件不会用。在哪交流下
- 我有一个100万的数据,我要把它写到数据库中如何提高效率。
- 请问在vb中,怎样得到sql server的任何表中用户的使用权限?
- 请问怎样才能将vb中的date型的内容转化为sql server的datetime型呀,谢谢大家了
- pb打不开库了,呜呜!!
- sql2005 sa登录总是报错。
- mssql数据库能不能设置上限,就是希望它最多只保存200条数据,多出来就自动删除
要想都三个都出来,就不用union ,同时生成三个记录集
它的值是去掉了相同的记录.改为: UNION ALL 你就明白了.
(
sjdxzt char(1)
)
insert into sb_ztb
select 1 union all
select 2 union all
select 2 union all
select 2 union all
select 1 union all
select 3select * from sb_ztbselect bjdj01=(select count(*) from sb_ztb where sjdxzt='1'),
bjdj02=(select count(*) from sb_ztb where sjdxzt='2'),
bjdj03=(select count(*) from sb_ztb where sjdxzt='3')
也可以用这种方式
create table #sb_ztb
(
sjdxzt char(1)
)
insert into #sb_ztb
select 1 union all
select 2 union all
select 2 union all
select 2 union all
select 1 union all
select 3select * from #sb_ztbselect bjdj01,
bjdj02,
bjdj03
from
(select count(*) as bjdj01 from #sb_ztb where sjdxzt='1') as a,
(select count(*) as bjdj02 from #sb_ztb where sjdxzt='2') as b,
(select count(*) as bjdj03 from #sb_ztb where sjdxzt='3') as c