SQL查询:在Price表中获取新价格 [英] SQL Query: Get new price in Price table

查看:103
本文介绍了SQL查询:在Price表中获取新价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我的表格如下:

 创建  PRODUCT_PRICE 

ID varchar 10 null
单位 varchar 10 null
价格整数 null
DateFrom datetime null





我在此表中输入数据,例如

 Row1:插入 PRODUCT_PRICE(ID,单位,价格,日期来自)'  1','  Single' 10000 '  2012-01-15'
第2行: 插入 PRODUCT_PRICE(ID,Unit,Price,DateFrom)' 1'' Double' 18000 ' 2012-01- 15'
第3行:插入 PRODUCT_PRICE(ID,Unit,Price,DateFrom) values ' 2'' 单个' 20000 null
第4行:插入 PRODUCT_PRICE(ID,Unit,Price,DateFrom)' 1'' Single' 13000 ' 2012-02-15'
第5行:插入 PRODUCT_PRICE(ID,单位,价格,DateFrom)' 1'' < span class =code-string> Double', 22000 ' 2012-02-15'







I希望有一个查询结果相同的图片

http://upanh.com/view/?s=null&id=9vpa2b2odoy

意味着我只得到DateFrom是Max( Row3,Row4,Row5)



请帮帮我

谢谢,

SaiDon

解决方案

您发布的图片链接不起作用。



您可以尝试



 选择 * 
来自 PRODUCT_PRICE
其中 DateFrom =(选择 Max DateFrom 来自 PRODUCT_PRICE)
< span class =code-keyword>或 DateFrom null


Dear all,

I have table such as:

create table PRODUCT_PRICE
(
ID		varchar (10)	not null,
Unit		varchar (10)	not null,		
Price		integer		not null,
DateFrom	datetime	null
)



I input data in this table such as

Row1: Insert PRODUCT_PRICE (ID, Unit, Price, DateFrom) values ('1', 'Single', 10000, '2012-01-15')
Row2: Insert PRODUCT_PRICE (ID, Unit, Price, DateFrom) values ('1', 'Double', 18000, '2012-01-15')
Row3: Insert PRODUCT_PRICE (ID, Unit, Price, DateFrom) values ('2', 'Single', 20000, null )
Row4: Insert PRODUCT_PRICE (ID, Unit, Price, DateFrom) values ('1', 'Single', 13000, '2012-02-15')
Row5: Insert PRODUCT_PRICE (ID, Unit, Price, DateFrom) values ('1', 'Double', 22000, '2012-02-15')




I want have a query with results same picture
http://upanh.com/view/?s=null&id=9vpa2b2odoy
Mean I only get DateFrom is Max (Row3, Row4, Row5)

Please help me
Thanks,
SaiDon

解决方案

The picture link you posted is not work.

You can try

select *
from PRODUCT_PRICE
where DateFrom = (select Max DateFrom from PRODUCT_PRICE)
or DateFrom is null


这篇关于SQL查询:在Price表中获取新价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆