admin管理员组文章数量:1278720
I have this table in informix:
CREATE TABLE PARTICIPACION(
idParticipacion serial not null,
idPersona integer,
fechaAlta datetime year to second NOT NULL,
fechaModificacion datetime year to second,
idTipoParticipacion smallint,
isEstado smallint NOT NULL,
descripción varchar(150)
);
The same idPersona can appear several times.
I need a query that returns the idPersona that have exactly two records and whose fechaModificacion is separated by one year or less.
I have this table in informix:
CREATE TABLE PARTICIPACION(
idParticipacion serial not null,
idPersona integer,
fechaAlta datetime year to second NOT NULL,
fechaModificacion datetime year to second,
idTipoParticipacion smallint,
isEstado smallint NOT NULL,
descripción varchar(150)
);
The same idPersona can appear several times.
I need a query that returns the idPersona that have exactly two records and whose fechaModificacion is separated by one year or less.
Share Improve this question asked Feb 24 at 7:18 Cybor696Cybor696 511 silver badge2 bronze badges 1- 1 Did you try something? Please show some code. – Yoji Commented Feb 24 at 8:05
1 Answer
Reset to default 2With exactly 2 values to match, you can use MIN()
and MAX()
to compare both:
SELECT idPersona
FROM PARTICIPATION
GROUP BY idPersona
HAVING COUNT(1) = 2
AND MAX(fechaModificacion) <= MIN(fechaModificacion) + INTERVAL (1) YEAR TO YEAR;
本文标签: sqlQuery with datetime in informixStack Overflow
版权声明:本文标题:sql - Query with datetime in informix - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741289171a2370448.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论