DROP TABLE IF EXISTS `v_chokin`;
DROP VIEW IF EXISTS `v_chokin`;

CREATE OR REPLACE VIEW `_mydb_kakeibo`.`v_chokin` AS 
SELECT m_chokin.*, m_ginkou.c_ginkouName, m_ginkou.c_ginkouDisplayOrder,
r_shurui.c_shurui, r_mankitype.c_mankitype
FROM m_chokin
LEFT OUTER JOIN m_ginkou ON m_chokin.id_ginkou = m_ginkou.id_ginkou
LEFT OUTER JOIN r_shurui ON m_chokin.id_shurui = r_shurui.id_shurui
LEFT OUTER JOIN r_mankitype ON m_chokin.id_mankitype = r_mankitype.id_mankitype
WHERE m_chokin.c_delete = 0;

DROP TABLE IF EXISTS `v_keiyakusha`;
DROP VIEW IF EXISTS `v_keiyakusha`;

CREATE OR REPLACE VIEW `_mydb_kakeibo`.`v_keiyakusha` AS 
SELECT DISTINCT `m_chokin`.`id_account` AS `id_account`,`m_chokin`.`c_keiyakuSha` AS `c_keiyakuSha`
FROM `m_chokin` where c_delete = 0;
