这样的查询结构应该怎么写sql语句?

客户名称 总用邮费用 竞争对手 使用竞争对手费用
电信局 1000 移动 2000
连通 1300
邮政局 2000
XXX 300 XX1 12
XX2 33
XX3 43
就是select 里面有一项是多个值,能不能用sql语句作出来???
[185 byte] By [strayatman-strayatman] at [2008-5-21]
# 1
用左连接吧,对同一个表取不同字段,然后左联,同时用CASE,估计可以实现。不过没试过,提个建议。
matboy at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 2
select 客户名称,总用邮费用,竞争对手,使用竞争对手费用 from tablename
order by 客户名称
tj_dns-愉快的登山者 at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 3
select 客户名称,case when 总邮资费用 not in (select 总邮资费用 where 客户名称='电信局') then 总邮资费用 else '' as 总邮资费用 ,竞争对手,使用竞争对手费用 from tablename where where 客户名称='电信局'
union all
select 客户名称,case when 总邮资费用 not in (select 总邮资费用 where 客户名称='xxx) then 总邮资费用 else '' as 总邮资费用 ,竞争对手,使用竞争对手费用 from tablename where where 客户名称='xxx'
------这种方法对于数量不大的还行,如果数据多,就建个存储过程,利用for循环和参数来调用吧。
lyyrw-咋暖还寒 at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 4
把你的表结构写出来。
================================================================
★★
bowlder-玩石 at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 5
to:strayatman (strayatman)
TSQL有非常强大的功能,把表结构贴出来看看,应该没有问题实现你的功能!
leimin-黄山光明顶 at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 6
case能解决,lyyrw已经给了示例
airzhy-haha at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 7
表结构都没有怎么写SQL语句?
bjay-ben at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...
# 8
我来学习一下
mymmsc-热血老猫 at 2007-10-24 > top of Msdn China Tech,MS-SQL Server,疑难问题...