首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这样的查询怎么写?

2012-02-13 
这样的查询如何写??这样的SQL如何得到?标项货品明细码供应商ID报价价格报价时间bp_idbp_pidbp_saleridbp_p

这样的查询如何写??
这样的SQL如何得到?

标项                                 货品明细码               供应商ID                 报价价格           报价时间
bp_id                             bp_pid               bp_salerid           bp_price       bp_bjdate
20070202131249_016   200702017_008     20070123133123     100       2007-2-6   10:21:15
20070202131249_016   200702017_011     20070123133123     50       2007-2-6   10:21:15
20070202131249_016   200702017_008     20070123133103     200       2007-2-6   10:19:15
20070202131249_016   200702017_011     20070123133103     150       2007-2-6   10:19:15  

我想得到供应商的ID
标项20070202131249_016   所有物品报价总和最近的供应商ID   如果两个供应商报价相同取
报价时间早的一个
SQL如何写??

[解决办法]
select bp_id,bp_salerid,sum(bp_price) as bp_price,min(bp_bjdate) as bp_bjdate into # from tablename group by bp_id,bp_salerid
select * from # t where not exists(select 1 from # where bp_price> t.bp_price and bp_bjdate <t.bp_bjdate and bp_id=t.bp_id)
drop table #

热点排行