PostgreSQL
 sql >> Teknologi Basis Data >  >> RDS >> PostgreSQL

Beberapa Rumus di PostgreSQL

SQLFiddle

select
  2.5*((r-i)/(r+(6*i)-(7.5*n)+1)) as tera,
  (r-(2*i)-n)/(r+(2*i)-n) as tera2
from
  (
  select
    sum(case when wavelength between 340 and 345 then reflectance end) as r,
    sum(case when wavelength between 350 and 355 then reflectance end) as i,
    sum(case when wavelength between 360 and 365 then reflectance end) as n
  from
    test
  ) vars

Untuk beberapa tabel, Anda dapat menggunakan sesuatu seperti:

select
  table_name,
  2.5*((r-i)/(r+(6*i)-(7.5*n)+1)) as tera,
  (r-(2*i)-n)/(r+(2*i)-n) as tera2
from
  (
  select
    table_name,
    sum(case when wavelength between 340 and 345 then reflectance end) as r,
    sum(case when wavelength between 350 and 355 then reflectance end) as i,
    sum(case when wavelength between 360 and 365 then reflectance end) as n
  from
    (
      select 'table 1' as table_name, * from test
      union all
      select 'table 2', * from test
      union all
      select 'table 3', * from test      
      union all
      select 'table 4', * from test  
    ) as all_tables
  group by
    table_name
  ) vars

SQLFiddle

Anda hanya perlu mengubah nama tabel menjadi nama sebenarnya dan mengulang union all sebanyak yang Anda butuhkan.



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara meminta UUID untuk postgres

  2. Fungsi sebagai parameter untuk fungsi lain di Postgres

  3. Mengoptimalkan GROUP BY + COUNT DISTINCT pada kolom jsonb yang tidak bersarang

  4. Postgres :Tidak ditemukan Driver yang cocok untuk jdbc

  5. Mengoptimalkan banyak gabungan