Find missing rows based on two columns and date series – Postgresql -


i try search missing periods (year , month = 201508) , each employe signature 'aa'. searching 1 column works:

select *  generate_series('2014-12-31','2016-12-31', interval '1 month') dates  to_char(dates,'yyyymm') not in (select ts_per ts) 

http://sqlfiddle.com/#!15/0cafa/4

the output of missing month

like march missing.

but want output per employee well. missing record jan , march jd , feb , march. bb missing 3 months.

jd 201502 jd 201503  201501 201503 bb 201501 bb 201502 bb 201503 

here newbie attempt add employee search fails:

http://sqlfiddle.com/#!15/0cafa/5

error: syntax error

tia clue,

sorry not sure want... recommend outer join

select * generate_series('2015-01-01','2015-03-01', interval '1 month') dates left outer join ts on concat(ts_sign,ts_per) = concat(ts_sign,to_char(dates,'yyyymm')) 

to see same , missing, , :

select * generate_series('2015-01-01','2015-03-01', interval '1 month') dates left outer join ts on concat(ts_sign,ts_per) = concat(ts_sign,to_char(dates,'yyyymm')) ts_per null 

to see missing


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -