当前位置:编程学习 > C#/ASP.NET >>

简单的 SQL问题.

酒店代码   销售价    返点

10010018   666.0   0.2100
10010017   360.0   0.2000
10010015   250.0   0.2400
10010015   560.0   0.1600
10010012   170.0   0.1600
10010011   160.0   0.2000


------------------------------------------------
我要查询出 同一酒店代码下,返点最高,价格最低的信息.(三列都要查询出来)


--------------------编程问答-------------------- 这个题目不严谨,
仔细想想吧!!

除非告诉我们价格和返点之间有什么关系. --------------------编程问答-------------------- select max(返点),min(销售价) from table group by 酒店代码 

没有测试 --------------------编程问答-------------------- 不行吧!两个条件不一定能同时满足 --------------------编程问答-------------------- select  酒店代码,min(销售价),max(返点) from table where 酒店代码 =? --------------------编程问答--------------------
select [code],max(returndot),min([Price]) from test  group by [code],[returndot],[Price]
--------------------编程问答-------------------- up up up --------------------编程问答-------------------- 返点最高的,不一定售价最低,售价最低的不一定返点最高,只能分别查询。
select * from 表名 where 酒店代码=要查询的代码 and 销售价 in (select top 5 销售价 from 表名 order by 销售价 desc)and 返点 in (select top5 返点 from 表名 order by 返点 asc)
--------------------编程问答-------------------- select 酒店代码,max(返点),min(销售价) from 表名 group by 酒店代码 --------------------编程问答--------------------
select * from 表名 where 酒店代码=要查询的代码 and 销售价 in (select top 5 销售价 from 表名 order by 销售价 desc) order by 返点 asc
--------------------编程问答--------------------
select *
from 
(select row=row_number()over(partition by 酒店代码 order by 返点 desc, 销售价 asc),* from Table1)t
where row=1
--------------------编程问答-------------------- --------------------编程问答-------------------- 先把返点最高,价格最低的分别查出来,然后把结果连起来应该可以了 --------------------编程问答-------------------- 没有给出一个判定标准,
这个题目无解!! --------------------编程问答-------------------- 这个必须告诉销售价与返点的关系,否则无解

--------------------编程问答-------------------- 感觉题目条件不够 --------------------编程问答--------------------
引用 14 楼 hhzichen 的回复:
这个必须告诉销售价与返点的关系,否则无解


恩,这个SQL无法实现.已经采用其它办法解决了.谢谢大家的支持 --------------------编程问答-------------------- 樓主咋還不出面解釋呢 --------------------编程问答-------------------- 一头雾水 --------------------编程问答-------------------- 返点最高的,价格一定最低吗?或者价格最低的,返点一定最高?还是要返回几条数据让用户自己选择?好像楼主没有说清楚啊... --------------------编程问答-------------------- 多条件查询· --------------------编程问答--------------------

declare @table table 
(酒店代码 varchar(11),销售价 numeric(4,1),返点 numeric(5,4))
insert into @table
select '10010018',666.0,0.2100 union all
select '10010017',360.0,0.2000 union all
select '10010015',250.0,0.2400 union all
select '10010015',560.0,0.1600 union all
select '10010012',170.0,0.1600 union all
select '10010011',160.0,0.2000

select 酒店代码,
最低价=min(销售价),最高返点=max(返点) 
from @table group by 酒店代码
/*
酒店代码        最低价            最高返点
----------- -------------- ---------------------------------------
10010011    160.0          0.2000
10010012    170.0          0.1600
10010015    250.0          0.2400
10010017    360.0          0.2000
10010018    666.0          0.2100
*/

貌似没有要求最低价和最高返点必须是同一行的... --------------------编程问答-------------------- 大大大大大大大大大大大大大大大大 --------------------编程问答-------------------- 学习学习
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,