Error: sintaxis de entrada no válida para entero: ""
Frecuentes
Visto 55,972 equipos
9
Tengo esta mesa tbl_buku
:
id_buku judul_buku tahun_buku
1 Bioogi 2010
2 Fisika 2010
3 Informatika 2012
4 Kimia 2012
I use query like this, but I am getting an error:
select case when t1.tahun_buku=t2.tahun_buku then ''
else t1.tahun_buku end tahun_buku,t1.judul_buku
from tbl_buku t1 left join tbl_buku t2
on t1.id_buku-1=t2.id_buku;
I want to show table like this:
tahun_buku judul_buku
2010 Biologi
Fisika
2012 Informatika
Kimia
¿Cómo lograrlo?
2 Respuestas
7
I think the problem in your query is that tahun_buku
es de datatype int
and you are trying to select an empty string
(''
).
You have to workarounds:
Cambiar y guardar tahun_buku
para ser varchar
(2010,2012..will be consider as strings I dont know if it is ok)
Conjunto:
select case when t1.tahun_buku=t2.tahun_buku then null else t1.tahun_buku end tahun_buku,t1.judul_buku
from tbl_buku t1 left join tbl_buku t2
on t1.id_buku-1=t2.id_buku;
contestado el 28 de mayo de 14 a las 13:05
3
Use el función de ventana
lag()
to get values from the previous row.Utilice la herramienta
NULL
for "empty" values in a columna numérica - me gusta @apomene already suggested.
La cuerda vacía''
solo se puede usar en tipos de personajes comotext
orvarchar
.Utilice la herramienta
NULLIF()
in this particular case to substitute the NULL value.
SELECT NULLIF(lag(tahun_buku) OVER (ORDER BY tahun_buku, judul_buku)
, tahun_buku) AS tahun_buku
, judul_buku
FROM tbl_buku
ORDER BY tahun_buku, judul_buku;
contestado el 23 de mayo de 17 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas sql postgresql null string window-functions or haz tu propia pregunta.
Es posible que desee utilizar
lag()
window function. Details here: postgresql.org/docs/current/static/functions-window.html - Ihor Romanchenkoplease give me example. - Trisna
SQL is the wrong tool for suppressing repeated values in a column. That's what report writers are for. (You have a presentation-level problem, not a database problem.) - Mike Sherrill 'Cat Recall'