Question

the create table query is :

create table catalog (id int, ra double, decl double , zone int);

the zone value is calculated from decl using formula below:

CAST(FLOOR(decl) AS INTEGER),

i have insert all id,ra,decl values of the table, then I have to calculate zone values,

how to calculate the table's zone value in a sql query?

**in another table extractedcatalog, i want to calculate y from ra,decl in sql:

update extractedcatalog set x= (cos(radians(decl))cos(radians(ra))); but responsed: connection terminated! is there any problem with my sql?*

Thanks very much!

Was it helpful?

Solution

Haven't you done it already?

update catalog set zone=CAST(FLOOR(decl) AS INTEGER);

if this doesn't work, try doing it as a self join:

update catalog set zone=CAST(FLOOR(a.decl) AS INTEGER)
from catalog a
where 1=1;

I don't have a DB instance available at the moment so you'll have to check these yourself.

As another person has pointed out, you don't really need to store zone at all, you can just return it as a calculated value

select CAST(FLOOR(a.decl) AS INTEGER) as zone
from catalog a
where 1=1;

OTHER TIPS

you will want to do something like this:

update catalog set zone = CAST(FLOOR(decl) AS INTEGER);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top