How to perform division in Hive with a Select statement

13,499

Your first line should be

SELECT 1/CAST(my_number as double) FROM table_number;

Although I think it will be cast implicitly if you just do

SELECT 1/my_number FROM table_number;
Share:
13,499
bkieler
Author by

bkieler

Updated on November 29, 2022

Comments

  • bkieler
    bkieler 11 months

    I'm writing this in Hive. I have a table that just holds one number. I'll call the table that holds the number table_number and the actual number is my_number.

    In a different table that doesn't yet exist, I need to enter a decimal number that is 1/my_number.

    I have tried SELECT CAST((1/(SELECT my_number FROM table_number)) as double); I get a parse exception "cannot recognize input near 'cast' '(' '('

    I've also tried double(1/(SELECT my_number FROM table_number)); I get another parse exception "cannot recognize input near 'double' '(' 'Select'

    I'm at a total loss as to how to do this. Can anyone give me some division examples that also use a select statement for one of the numbers?