#!/bin/bash
source $HOME/.gamerc

for set in 1 2 3 4 5 6 7 11 12 13 14 15 21 22 23 24 25 26 27 28 29 30; do
	echo GAMEDB${set} | colorize yellow black
	#ssh GAMEDB${set} "psql -U postgres G1DB${set} -c \"SELECT item_id, mission_state, COUNT(*) FROM player_niap_db WHERE item_id IN (404301,404304) AND player_id IN (SELECT player_id FROM order_mails_cache_bak WHERE product_id IN ('com.xlegend.grandfantasia.global_p2_m36_490','com.xlegend.grandfantasia.global_p1_m36_490','com.xlegend.grandfantasia.global_p201_m36_490')) GROUP BY item_id, mission_state ORDER BY item_id, mission_state;\""
	#ssh GAMEDB${set} "psql -U postgres G1DB${set} -c \"SELECT player_id, item_id, mission_state FROM player_niap_db WHERE item_id IN (404301,404304) AND player_id IN (SELECT player_id FROM order_mails_cache_bak WHERE product_id IN ('com.xlegend.grandfantasia.global_p2_m36_490','com.xlegend.grandfantasia.global_p1_m36_490','com.xlegend.grandfantasia.global_p201_m36_490')) AND mission_state IN (0,1) ORDER BY player_id, item_id;\""
	ssh GAMEDB${set} "psql -U postgres G1DB${set} -c \"COPY (SELECT '${set}'::text as set_id, account_name as xluser_id, account_id, player_id, item_id, mission_state FROM player_niap_db n LEFT JOIN player_characters p ON (n.player_id=p.id) WHERE item_id IN (404301,404304) AND player_id IN (SELECT player_id FROM order_mails_cache_bak WHERE product_id IN ('com.xlegend.grandfantasia.global_p2_m36_490','com.xlegend.grandfantasia.global_p1_m36_490','com.xlegend.grandfantasia.global_p201_m36_490')) AND mission_state IN (0,1) ORDER BY player_id, item_id) TO '/tmp/1007_20211117_2_s${set}.csv' HEADER CSV;\""
done
