Home > database >  update a range of rows in a mysql table via many colums
update a range of rows in a mysql table via many colums

Time:06-03

I have a table with year, month, day and request columns. I need to update a range that in the table below starts at year = 2022, month = 6, day = 7 and ends with year = 2022, month = 9, day = 16. The request value must be = 9 and its insertion depends on dow

year| month| day| dow|req|
---- ------ ---- ---- --- 
2022|  6   |  4 | sat| 5 |
2022|  6   |  5 | sun| 5 |
2022|  6   |  6 | mon| 5 |
2022|  6   |  7 | tue| 9 |
2022|  6   |  8 | wed| 9 |
2022|  6   |  9 | thu| 9 |
2022|  6   | 10 | fri| 9 |
---  ---  ---  ---  ---  
2022|  9   | 13 | tue| 9 |
2022|  9   | 14 | wed| 9 |
2022|  9   | 15 | thu| 9 |
2022|  9   | 16 | fri| 9 |
2022|  9   | 17 | sat| 3 |
2022|  9   | 18 | sun| 3 |
2022|  9   | 19 | mon| 3 |
---  ---  ---  ---  --- 

and this is my query

x_req = 'mon'
query = "UPDATE `calendar` SET '%s' = '%s' WHERE year = '%s' AND (month BETWEEN '%s' AND '%s') AND dow = '%s' " %(request, nbr, year, s_month, e_month, x_req)
Functions.handleQuery(self, query)

But this query also updates June 3 as well as November 23 and 30. How can I make the query start and end on the chosen days

CodePudding user response:

where (year,month,day) >= (2022,6,7) and (year,month,day) <= (2022,9,16)
  • Related