如何将两个不同的查询条件得到的结果存到一个数据集里??

zosky 2003-02-08 10:43:02
查询一张表,最后得到像这样的结果
col1 col2
a d1
b d2
c d3 d4

col1和col2的查询条件不同,请问sql该怎么写?
...全文
32 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenchangfu 2003-02-15
  • 打赏
  • 举报
回复
select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II
Where OBcbFlag='Rcv'
and OalId='A2'
and Rspcode='30'
and Datemsg like '200301%'
and InExCode='Intra'
and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
and Left(BankCode,6) in ('080313','080402')
Group by BankCode , Rspcode
order by BankCode,Rspcode

可以用
select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II
Where OBcbFlag='Rcv'
and OalId='A2'
and Rspcode='30'
and Datemsg like '200301%'
and InExCode='Intra'
and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
and Left(BankCode,6) in ('080313','080402')
AND Rspcode in (12,14,30。。。)
Group by BankCode , Rspcode
order by BankCode,Rspcode
zosky 2003-02-09
  • 打赏
  • 举报
回复
好啊,实际就是统计各项数据,现在大概有四十多个吧,是分开的;
现在要弄到一个数据集里(四十多列),下面是现在用的的sql


select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II
Where OBcbFlag='Rcv'
and OalId='A2'
and Rspcode='12'
and Datemsg like '200301%'
and InExCode='Intra'
and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
and Left(BankCode,6) in ('080313','080402')
Group by BankCode
order by BankCode


select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II
Where OBcbFlag='Rcv'
and OalId='A2'
and Rspcode='14'
and Datemsg like '200301%'
and InExCode='Intra'
and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
and Left(BankCode,6) in ('080313','080402')
Group by BankCode
order by BankCode


select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II
Where OBcbFlag='Rcv'
and OalId='A2'
and Rspcode='30'
and Datemsg like '200301%'
and InExCode='Intra'
and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
and Left(BankCode,6) in ('080313','080402')
Group by BankCode
order by BankCode
chenchangfu 2003-02-09
  • 打赏
  • 举报
回复
不明白你的问题意思
能贴除要查的表原始数据和要的结果吗?
CrazyFor 2003-02-08
  • 打赏
  • 举报
回复
select id,col1,'' as col2 from table where ....
union all
select id,'' as col1,col2 from table where ...
pengdali 2003-02-08
  • 打赏
  • 举报
回复
哈哈!
认真学习。。。
pengdali 2003-02-08
  • 打赏
  • 举报
回复
学习!
j9988 2003-02-08
  • 打赏
  • 举报
回复
select 剩下的抄上面两位的。
pengdali 2003-02-08
  • 打赏
  • 举报
回复
select id,col1,'' col2 from 表 where 条件
union all
select id,'',col2 from 表 where 条件

34,588

社区成员

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

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