简体   繁体   中英

SQL nested case Statement for rounding

I have an SQL statement that selects 4 pieces of data.

First is a name(String).

The other 3 are numbers(floats).

I'm having issues adding a case statement that looks at the name, and based off the name, it applys rounding rules, there can be up to three rounding rules for each name, so the case statement would have to be nested?

How would I go about this? Could you give an example? Would be something like this

case name_field
        when name_field = apple then
             when apple < 5 then
                 round(apple)

Thanks,

Could you post any details about your data or any issues you are having? You seem to be on the right page. Here's an example of a nested case statement which can be tested here .

SELECT
  *,
  CASE 
    WHEN Country = "UK" THEN
        CASE
            WHEN City = "London" THEN "A"
            ELSE "B"
        END
        ELSE "C"
   END AS something
FROM Customers;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM