Hello, I'm developing an online subscription system for a client, and I've come across a lot of difficulties. I will explain a bit about the system's operation and what difficulties I am having.
- My system has 8 plans, registered in a table called Plans.
- Each signature can have more than one plan.
- A signature can contain more than one user.
So long, OK. However, I'm having difficulty sorting some items. I need to list all records of Registered Users. However, they should list only those with the regular signature. This is the first difficulty.
What defines the regular situation is a record in a table called SignaturePlane, which stores the ID of the signature and plan, and contains a flag called Situation, which if equal to 3, is OK. However, in this table, there is no user ID, since it is in another table, called UserName. I'm not sure how to capture this information in the same query I'm already doing:
This query brings the active users of Curitiba city:
SELECT * FROM sistema_cliente c INNER JOIN sistema_assinatura_cliente ac ON ac.cliId = c.cliId WHERE cliAtivo = 'S' AND cliExcluido = 'N' AND cidId IN (SELECT cidId FROM sistema_assinatura_cidade WHERE cidId IN (2878)) LIMIT 0,15
How can I just bring users who are on subscriptions that have plans that are on regular payments? I do not know if I was clear, rs.
Here are the tables and an example of a cadastre to illustrate:
CLIENTS
CREATE TABLE IF NOT EXISTS 'client_client' ('cliId' int (11) NOT NULL, 'cliName' varchar (255) NOT NULL, 'cliActive' enum ('S', 'N') NOT NULL, 'cliExcluido' enum ('S', 'N') NOT NULL) ENGINE = MyISAM AUTO_INCREMENT = 3 DEFAULT CHARSET = utf8;
INSERT INTO 'client_client' ('cliId', 'cliName', 'cliActive', 'cliExcluido') VALUES (1, 'Maykel Esser', 'S', 'N');
PLANS
CREATE TABLE IF NOT EXISTS 'plan_name' ('plaId' int (11) NOT NULL, 'plaTitulo' varchar (255) NOT NULL, 'plaModality' enum ('M', 'T', 'S', 'A') NOT NULL, 'plaValor' float NOT NULL,
'plaDataCadastro' datetime NOT NULL, 'plaAtivo' enum ('S', 'N') NOT NULL, 'plaExcluded' enum ('S', 'N') NOT NULL) ENGINE = MyISAM AUTO_INCREMENT = 12 DEFAULT CHARSET = utf8;INSERT INTO 'system_plans' ('plaId', 'plaTitulo', 'plaModalidade', 'plaValor', 'plaDataCadastro', 'plaAtivo', 'plaExcluido') VALUES (1, 'Traditional', 'M', 19.9, '2017-04-11 00:00:00', 'S', 'N'), (2, 'Traditional', 'T', 49.9, '2017-04-11 00:00:00', 'S', 'N'), (3, 'Traditional', 'S', 89.9, '2017-04-11 00:00:00', 'S', 'N'), (4, 'Traditional', 'A', 129.9, '2017-04-11 00:00:00', 'S', 'N'), (5, 'Office', 'M', 59.9, '2017-04-11 00:00:00', 'S', 'N'), (6, 'Office', 'T', 149.9, '2017-04-11 00:00:00', 'S', 'N'), (7, 'Office', 'S', 269.9, '2017-04-11 00:00:00', 'S', 'N'), (8, 'Office', 'A', 389.9, '2017-04-11 00:00:00', 'S', 'N'), (9, 'Benefits' - Bronze, 'M', 3, '2017-04-11 00:00:00', 'S', 'N'), (10, 'Benefits' - 'Silver', 'M', 7, '2017-04-11 00:00:00', 'S', 'N'), (11, 'Benefits' - 'Gold', 'M', 14, '2017-04-11 00:00:00', 'S', 'N');
SIGNATURES
CREATE TABLE IF NOT EXISTS 'system_name' ('assId' int (11) NOT NULL, 'assDataCadastro' datetime NOT NULL, 'assAtive' enum ('S', 'N') NOT NULL, 'asExcluded' enum ('S', 'N') NOT NULL) ENGINE = MyISAM AUTO_INCREMENT = 5 DEFAULT CHARSET = utf8;
INSERT INTO 'enrollment_name' ('assId', 'enrollment_address', 'Assertive', 'AssExcluded') VALUES (1, '2017-04-14 22:42:33', 'S', 'N');
SIGNATURE-CLIENT
CREATE TABLE IF NOT EXISTS 'customer_system' ('ascId' int (11) NOT NULL, 'assId' int (11) NOT NULL, 'cliId' int (11) NOT NULL) ENGINE = MyISAM AUTO_INCREMENT = 5 DEFAULT CHARSET = utf8;
INSERT INTO 'customer_system' ('ascId', 'assId', 'cliId') VALUES (1, 1, 1);
PLAN SIGNATURE
CREATE TABLE IF NOT EXISTS 'plan_name' ('aspId' int (11) NOT NULL, 'aspSituation' int (1) NOT NULL,
'aspDataVencer' int (2) NOT NULL, 'assId' int (11) NOT NULL,
'plaId' int (11) NOT NULL) ENGINE = InnoDB AUTO_INCREMENT = 6 DEFAULT CHARSET = utf8;INSERT INTO 'system_info_name' ('aspId', 'aspSituation', 'aspDataVencimento', 'assId', 'plaId') VALUES (1, 1, 0, 1, 1), (2, 1, 0, 1, 9);