我正在尝试返回一个结果集,其中包含来自另一个表的动态字段的分隔列表。它似乎正在工作,但即使我多次复制同一行,结果也只返回一行。
这是我的查询:
SELECT export_rules.*, GROUP_CONCAT( CAST( CONCAT( export_rule_fields.key, ': ', export_rule_fields.value ) AS char ) SEPARATOR '|') AS fields FROM export_rules
JOIN export_rule_fields ON export_rules.id = export_rule_fields.export_rule_id
WHERE export_rules.output_type = "email"
AND (export_rules.frequency = "daily"
AND export_rules.last_execution < TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))
AND (export_rules.cron_expression = "25 11 * * *"
OR export_rules.cron_expression = "30 11 * * *" ))
OR (export_rules.frequency = "weekly"
AND export_rules.last_execution < TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 WEEK))
AND (export_rules.cron_expression = "25 11 * * 5"
OR export_rules.cron_expression = "30 11 * * 5" ))
OR (export_rules.frequency = "monthly"
AND export_rules.last_execution < TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))
AND (export_rules.cron_expression = "25 11 15 * *"
OR export_rules.cron_expression = "30 11 15 * *" ))
GROUP BY export_rules.id
它应该通过其相应的表达式(该部分有效)获取一个 cron 列表,然后将它们与他们的字段一起吐出,但我认为 GROUP_CONCAT 或连接对于每个导出规则都有多行的事实正在抛弃它。