I have a table with share prices of different companies for each date. The fields are
Date | Symbol | Closing_Rate.
Now I have added one more field to this table Previous Day Closing Rate.
Date | Symbol | Closing_Rate | Pre_Cls_Rate
Please help me for a query to update the previous date's closing rate to current date's field named "Pre_Cls_Rate" Thanks in advance
正如Strawberry所说,这是一种冗余,您无需添加新列即可从同一张表中获取另一行的数据,只需在要获取诸如以下内容的数据时更改查询:
select t1.*,t2.Closing_Rate as Pre_Cls_Ratefrom yourTable t1 inner JOIN yourTable t2 where t1.Symbol=t2.Symbol and t2.Date <= DATE(DATE_SUB(t1.Date, INTERVAL 1 DAY)`) and t2.Date > DATE(DATE_SUB(t1.Date, INTERVAL 2 DAY)`)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.