I am trying to figure out, if any number of group_contact results in a set group of numbers
This example data can be used to:
create table 'event' (`eventid` int (11) faucet AUTONCRment,` EventName ' Varchar (255) DEFAULT zero, primary key (`event id`)) engine = INNDOBI outangement = 2 DEFAULT CHARSET = latin1; - ----------------------------- Records of 'events' ----------- --- -------------- Start Include in `Events' Prices ('1', 'My Event'); COMMIT; - ----------------------------- Table structure for 'Events 2 group' - ---------- ------------------ Create the table 'Events 2 group' (`id 'int (11) tap etunement,' event id 'at (11) default faucet, group id int (11) ) Default Null, Primary Key (`ID`)) Engine = InDebb Outangement = 4 Default Charset = Latin 1; - ----------------------------- Record of 'Events 2 group' - ----------- - ---------------- Start Incorporate in the values of groups of 2 groups ('1', '1', '5'), ('2', '1', '3'), ('3', '1', '1') ; COMMIT; ----------------------------- Table structure for 'groups' - ---------- --- --------------- Tablets 'group' (`groupwide 'at (11) faucet AUTACCR,' groupname 'varchar (255) default null, primary (` group' `)) engine = InnoDB AUTO_INCREMENT = 6 DEFAULT CHARSET = latin1; ----------------------------- Record of `group` - --------------- ------------- start; 'Group' value ('1', 'Group 1'), ('2', 'Group 2'), ('3', 'Group 3'), ('4', 'Group 4' 5 ',' Group 5 '); COMMIT; Set FOREIGN_KEY_CHECKS = 1; Then ask this query:
SELECT GROUP_CONCAT (groups.groupid), IF (GROUP_CONCAT (groups.groupid) IN (1,2, 3), 'yes',' no ') as in' incidents' from groups' events leave events on 2 groups of incidents. AventID = Events Group 2. Invited left groups on groups 2 groups. Garamed = groups.groupid by group events. Events The first results column shows that in the event there are 5, 3 and 1 groups. The user's groups are 1, 2 and 3, so match 3 and 1. If I use group_concat () result? Simply use conditional aggregation: , how can I get it from 'yes'?
SELECT GROUP_CONCAT (groups.groupid), (when max ((1, 2, 3) in gt.group_id); then 'yes' and' Not 'end') as 'groups from events' events occur in 2 groups on events. Events.eventid = events2groups.eventid LEFT Join group events2groups.groupid = groups.groupid by GROUP events.eventid;
No comments:
Post a Comment