SQL语句显示数据问题!高手请来!顶者有分不够+++
select a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType] from AutoPrice a,AutoInfo b where a.auto_price > 130-5 and a.auto_price <130+5 and a.AutoID=b.AutoID group by a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType]
多表查询
a.[AutoID]是外键存的是编号
a.[auto_price]金额字段比方说138.9 138.9万的意思
b.[autoBrand] 系列字段比方说XX系列
b.[autoType] 详细型号字段比方说XX系列XX款XX型
现在在查询分析器中查出来的结构太多了我想改一下这语句!
比方说
AutoID 等于 1000 的这个商品
在数据表中有100条报价
我想指取1条!应该如何实现?请高手指点!
------解决方案--------------------select distinct a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType] from AutoPrice a,AutoInfo b where a.auto_price > 130-5 and a.auto_price <130+5 and a.AutoID=b.AutoID group by a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType]
------解决方案--------------------select top 1 a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType]
from AutoPrice a, AutoInfo b
where a.AutoID=b.AutoID and a.AutoID = 1000
and a.auto_price > 130-5 and a.auto_price <130+5
------解决方案--------------------你前边的确表达不清啊。。。你要报价最高那个?
------解决方案--------------------net_lhb() ( )
不是指显示一条!而是
如何 AutoID 等于 1000 的这个商品编号
在数据表中有100条这个编号的报价
我想指取1条显示!应该如何实现?
----------------------------------------
select distinct a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType] from AutoPrice a,AutoInfo b where a.auto_price > 130-5 and a.auto_price <130+5 and a.AutoID=b.AutoID group by a.[AutoID],a.[auto_price],b.[autoBrand],b.[autoType]
------解决方案--------------------select distinct a.[AutoID],avg(a.[auto_price]) as autoprice,b.[autoBrand],b.[autoType] from AutoPrice a,left join AutoInfo b on a.AutoID=b.AutoID where a.auto_price > 130-5 and a.auto_price <130+5 group by a.[AutoID],autoprice,b.[autoBrand],b.[autoType]
------解决方案--------------------在你的sql语句里面加入top1