مشاهدات PostgreSQL: الرجوع إلى حقل محسوب في حقل آخر محسوب

StackOverflow https://stackoverflow.com/questions/2385791

سؤال

لدي نفس السؤال مثل #1895500, ، ولكن مع postgresql وليس mysql.

كيف يمكنني تحديد عرض يحتوي على حقل محسوب ، على سبيل المثال:

 (mytable.col1 * 2) AS times_two

... وإنشاء حقل محسوب آخر يعتمد على الحقل الأول:

 (times_two * 2) AS times_four

...?

هل كانت مفيدة؟

المحلول

اعتمادًا على مدى ثقل Formla ، يمكنك استخدام مسمة فرعية:

select inner.*, times_two * 2 from
(select mycol * 2 as times_two from table) sub

أو أعد كتابة الحساب:

select mycol * 2, mycol * 2 * 2 from table

نصائح أخرى

استخدم هذا البيان

 
CREATE  VIEW  view_name as  SELECT  column_name*2 as new_col1 , column_name*4 as new_col2  from table_name ; 

select * from view_name ; 

If you want use this view column values. use following things 

create view new_viwe as select new_col1*2 as final_column from view_name ; 

select * from new_view ; 


مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top