数据库新手请教~~~~~~

fantast79 2003-10-30 05:58:57
问题:对于同一个表,我想把不同的条件查询出的结果作为一条记录放到一个临时表中,不知道这样的SQL语句怎么写。
例:
Table:tblA,
字段
Col1 Col2 Col3
数据:
1 2 3
2 1 3
2 2 1

我现在要求得到一个临时表,其记录情况(只有一条记录,每一下条件产生的结果是一个字段):Col1=2,Col2=1,Col3=3

请问这样的SQL语句该怎么写?

...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantast79 2003-10-31
  • 打赏
  • 举报
回复
to kinglccs(Amazon) :

如果我一个条件产生的是两个列呢?比如说我一个条件Col1=1,就要求得记录条数和合计呢?
saien 2003-10-30
  • 打赏
  • 举报
回复
up
kinglccs 2003-10-30
  • 打赏
  • 举报
回复
select (select count(*) from tbla where col1=1),(select count(*) from tbla where col1=2),(select count(*) from tbla where col1=3) into #temp
fantast79 2003-10-30
  • 打赏
  • 举报
回复
晕,我还写了好长一串怎么都没了:

例如:现有表tbla,其中有字段有Col1,col2,col3,其记录有:
col1 col2 col3
1 2 3
2 2 3
1 3 2

我要求得一个临时表#temp,临时表的字段1是表tbla的col1=1的记录条数,字段2是表tbla的col2=2的记录条数,字段3是表tbla的col3=3的记录条数,它们要作为一条记录。即:
#temp
字段一 字段二 字段三
2 2 2

请教各位了
pengdali 2003-10-30
  • 打赏
  • 举报
回复
Select * into #tmp from tblA where col1= 2 and col2 = 1 and col3 = 3

还是

Select * into #tmp from tblA where col1= 2 or col2 = 1 or col3 = 3

??
txlicenhe 2003-10-30
  • 打赏
  • 举报
回复
Select * into #tmp from tblA where col1= 2 and col2 = 1 and col3 = 3

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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