php - MySQL Conditional Select Replace Query -
i have found myself in need of replacing returned results mysql select query. have following table , data (simplified example purposes)
uid | duration | range | unique | stamp ----------------------------------------------------------------- 23 | d | 43 | 1 | 1 24 | d | 65 | 0 | 2 25 | d | 76 | 0 | 3 26 | d | 33 | 0 | 4 27 | d | 44 | 1 | 5 28 | d | 43 | 1 | 6 29 | d | 67 | 0 | 7 30 | d | 88 | 0 | 8 31 | d | 63 | 0 | 9
the stamp
column want replace on. rather simple text replace, wondering if possible run sort of user defined function on column , replace dynamically.
for example if data returned in stamp column 1, replace today's timestamp, if 2 yesterdays timestamp, 3, day before yesterdays , on , forth.
so question is, possible point replace
function processes value , returns replace with. or if not, there way accomplish this.
i post process returned data in php , make changes, millions of records returned, increase load time considerably.
edit make things bit clearer: want replace stamp column in data returned select query, not storing data anywhere, or replacing data in table. table remain unchanged.
thanks
absolutely possible:
update stamps set stamp = current_date - interval stamp - 1 day;
fiddle here. note have decrement stamp value 1 "minus 0 days" stamp of 1
. if remove - 1
, you'll end storing yesterday's date stamp
values of 1
.
update answer question doing on select
:
select current_date - interval stamp - 1 day stamps;
Comments
Post a Comment