Hello! For example, there is the following table:

ab A1|10| A2|11| A3|14| A4| 3| A5| 8| A6|12| 

How to write a query that returns all the elements of the column a, and those elements of the column b that are greater than 10? In this case, instead of the values ​​that are less than or equal to 10, it will be written "unsuccessful".

    1 answer 1

    something like this:

     select a, case when b > 10 then to_char(b, '999999') else 'неуд' end as b from table_name; 

    or even easier (thanks to @Vitalts for the hint )

     select a, case when b > 10 then b::text else 'неуд' end as b from table_name; 

    PS I have not tested this code ...

    • Error: the function to_char (integer) does not exist - Tolkachev Ivan
    • what is your version of postgreSQL? - MaxU September
    • PostgreSQL 9.4. - Tolkachev Ivan
    • try to_char(b, '99') ... - MaxU
    • Yes, it works that way. Thank! What is the maximum value you can put instead of 99? Numbers that are greater than 99 are displayed as ### - Tolkachev Ivan