I need to make quite a simple request to the database. My table ( table_bla ) looks like this:

Picture

In words, the query is: Select the first nonzero value in float_val , where fiel_id 208,209,210 for this obj_id . And if it is more than 1000, but less than 2000, then in the rev_val this obj_idб where field_id 402 , put 1.
If the selected value is more than 2000 but less than 5000, then in the rev_val this obj_idб where field_id 402 , put 2.
And more than 10,000, but less than 20,000 - 4 the rest is 402 = 5

  • What does "first" mean? "Not null" - this is NOT NULL or non-zero (I have not seen those in the picture). And in general, for this image to show what and how it should turn out as a result. And what for the picture? mysql (in the console), the request with the output to the console, copy / paste the text in question - that's all. In linux in xterm - mouse, in Windows - select, select copy in the corner menu, and paste in the browser. - alexlz

1 answer 1

Maybe my February question will help you.

 UPDATE stationery_request t1 SET t1.price = CASE t1.price WHEN NULL THEN 4 ELSE t1.price = t1.price END