limit

mysql limit with variable

梦想与她 提交于 2020-08-09 14:54:53
问题 i have error in my syntax : SET @start := 0; SELECT (ROUND((count(item))/2)) FROM car INTO @until; SELECT * from car limit @until OFFSET @start; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@until OFFSET @start' at line 1 anyone can help me? thanks 回答1: You cannot use a user-assigned variable ( @until ) in the LIMIT clause. A possible solution (a variation on this): SELECT (ROUND((count(item))/2)) FROM

mysql limit with variable

别等时光非礼了梦想. 提交于 2020-08-09 14:54:40
问题 i have error in my syntax : SET @start := 0; SELECT (ROUND((count(item))/2)) FROM car INTO @until; SELECT * from car limit @until OFFSET @start; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@until OFFSET @start' at line 1 anyone can help me? thanks 回答1: You cannot use a user-assigned variable ( @until ) in the LIMIT clause. A possible solution (a variation on this): SELECT (ROUND((count(item))/2)) FROM

Constrain lower limit of the result of a subtraction

吃可爱长大的小学妹 提交于 2020-08-08 06:59:04
问题 I want to subtract the values in a vector from a scalar. However, if the result is lower than zero I want to set the result to zero. I have tried using max , but it doesn't give me the expected result s # [1] 750.0 975.0 1125.0 1237.5 1312.5 1400.0 max(1050 - s, 0) # [1] 300 I expect result to be c(300, 150, 0, 0, 0, 0) 回答1: I suggest pmax : pmax(1050 - s, 0) # [1] 300 75 0 0 0 0 来源: https://stackoverflow.com/questions/3438049/constrain-lower-limit-of-the-result-of-a-subtraction