From: | Ertan Küçükoğlu <ertan(dot)kucukoglu(at)1nar(dot)com(dot)tr> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Alternative SQL |
Date: | 2018-01-13 22:26:07 |
Message-ID: | 000201d38cbd$8197c070$84c74150$@1nar.com.tr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello,
I am using PostgreSQL 10.1 64bit on Windows 10 x64 system.
My database have following tables in it:
robox=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------------------+-------+-------
public | aciliskapanis | table | robox
public | ameliyathaneler | table | robox
public | ameliyatlar | table | robox
public | errorlog | table | robox
public | guncellemetablolari | table | robox
public | hastalar | table | robox
public | kaphareketleri | table | robox
public | kullanici | table | robox
public | malzemeler | table | robox
public | params | table | robox
public | personel | table | robox
public | sayimbaslik | table | robox
public | sayimdetay1 | table | robox
public | sayimdetay11 | table | robox
public | sayimdetay12 | table | robox
public | sayimdetay2 | table | robox
public | sayimdetay3 | table | robox
public | sayimmakinalari | table | robox
public | sayimyazdir | table | robox
public | sifirlamalar | table | robox
public | updates | table | robox
(21 rows)
I am using following SQL:
select 'aciliskapanis', max(kayitzamani) from aciliskapanis where serino =
'00000000de7de681'
union
select 'sayimbaslik', max(kayitzamani) from sayimbaslik where serino =
'00000000de7de681'
union
select 'sayimdetay1', max(kayitzamani) from sayimdetay1 where serino =
'00000000de7de681'
union
select 'sayimdetay11', max(kayitzamani) from sayimdetay11 where serino =
'00000000de7de681'
union
select 'sayimdetay12', max(kayitzamani) from sayimdetay12 where serino =
'00000000de7de681'
union
select 'sayimdetay2', max(kayitzamani) from sayimdetay2 where serino =
'00000000de7de681'
union
select 'sayimdetay3', max(kayitzamani) from sayimdetay3 where serino =
'00000000de7de681'
union
select 'errorlog', max(kayitzamani) from errorlog where serino =
'00000000de7de681'
union
select 'kaphareketleri', max(kayitzamani) from kaphareketleri where serino =
'00000000de7de681'
union
select 'sifirlamalar', max(kayitzamani) from sifirlamalar where serino =
'00000000de7de681'
Above SQL gives me following result and this is what I wanted.
?column? max
sayimdetay2 2018-01-13 23:24:29
errorlog 2018-01-14 00:08:56
sayimbaslik 2018-01-14 00:10:36
sifirlamalar 2018-01-13 23:19:07
sayimdetay11 2018-01-13 23:15:58
sayimdetay1 2018-01-14 00:10:42
sayimdetay3 2018-01-13 23:19:20
aciliskapanis 2018-01-14 00:12:44
sayimdetay12 2018-01-14 00:13:11
kaphareketleri 2018-01-14 00:13:33
But, it is not dynamic. Meaning, I am not using information in
guncellemetablolari table. guncellemetablolari table holds table names as
records that needs to be queried in my database. These records may change in
time. What I would like is an SQL (not a database function, if possible)
which gives me same result as above using records in guncellemetablolari
where guncellenir column is false.
robox=# \dS guncellemetablolari;
Table "public.guncellemetablolari"
Column | Type | Modifiers
-------------+---------+-----------
adi | text | not null
guncellenir | boolean |
Indexes:
"guncellemetablolari_pkey" PRIMARY KEY, btree (adi)
robox=# select * from guncellemetablolari;
adi | guncellenir
----------------+-------------
ameliyatlar | t
hastalar | t
malzemeler | t
personel | t
aciliskapanis | f
sayimbaslik | f
sayimdetay1 | f
sayimdetay11 | f
sayimdetay2 | f
sayimdetay3 | f
sayimyazdir | f
errorlog | f
kaphareketleri | f
sifirlamalar | f
sayimdetay12 | f
(15 rows)
Any help is appreciated.
Thanks & regards,
Ertan Küçükoğlu
From | Date | Subject | |
---|---|---|---|
Next Message | Danilo | 2018-01-18 01:15:36 | Ajuda - insert into select com variavel |
Previous Message | Andreas Joseph Krogh | 2018-01-04 13:27:20 | Sv: More optimized SQL |