我试图在一次更新中将所有字段“ name”替换为“ name + 1”。例如,我希望2008年成为2009年,2009年成为2010年,等等。
我只做了一次替换:
UPDATE table
SET name = REPLACE(name, '2008', '2009');
但是,如果我想在2010年之前替换2009年,那将是错误的,因为它也会更改我上次请求的2009年。
这是我的数据库:
我如何才能在一个请求中将所有这些年份的“名称”增加而又没有冲突,也不能在最近一年之前开始?
感谢您的时间。
答案 0 :(得分:2)
只要列值为纯数字,即使其数据类型为varchar
,也不需要任何强制转换。
MySql 执行implicit casting:
update tablename
set name = name + 1;
请参见demo。
答案 1 :(得分:1)
只需使用casting
(对于数字类型,为无符号)
Private Sub MoveRowToEndOfTable()
Dim LastRow As Long
LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets(1).Range("A2:A" & LastRow, "G2:G" & LastRow).Copy
Dim wb As Workbook, wb_target As Workbook
'check if workbook is open already
For Each wb In Workbooks
If wb.Name = "BRN report Aggregator.xlsx" Then
Set wb_target = Workbooks("BRN report Aggregator.xlsx")
Exit For
End If
Next wb
'if not then open it
If wb_target Is Nothing Then
Set wb = Workbooks.Open("Path_to_file/BRN report Aggregator.xlsx")
End If
wb.Worksheets("New shares EOM").Range("a6000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll 'or xlPasteValues --depends on your needs
wb.Close True 'save and close if required
End Sub
考虑您的列(update table
set name = cast(name as unsigned) + 1;
)仅包含整数年份值。