2

我有一个包含 800 个查询的脚本。他们中的大多数人一无所获。

如何修改此脚本以了解哪些仅返回行

SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_notification_template` WHERE `name` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_notification_template` WHERE `push_title` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_notification_template` WHERE `message_title` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_queue` WHERE `push_title` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_queue` WHERE `message_title` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`xmlconnect_queue` WHERE `type` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`zizio_groupsale` WHERE `zizio_object_id` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`zizio_groupsale` WHERE `name` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`zizio_groupsale` WHERE `recurrence_child` LIKE '%1720%';
SELECT * FROM `theprint_depotlive-v16`.`zizio_groupsale` WHERE `recurrence_ancestor` LIKE '%1720%';
4

2 回答 2

1

一种方法是包含一个“查询标识符”作为结果集输出的第一列,例如一个序列号作为“键”。

SELECT 1 as q, t.* FROM foo t WHERE ... ;
SELECT 2 AS q, t.* FROM foo2 t WHERE ... ;

(有关如何在每个生成的语句中包含此唯一值的示例,请参阅我对您上一个问题的回答的更新。)

于 2012-08-31T22:50:19.367 回答
0

你可以做这样的事情,这将只返回具有行的查询:

SELECT
  '`theprint_depotlive-v16`.`xmlconnect_notification_template`' as table,
  '`name` LIKE \'%1720%\'' as condition,
  count(*) as count
FROM `theprint_depotlive-v16`.`xmlconnect_notification_template`
WHERE `name` LIKE '%1720%'

UNION

SELECT
  '`theprint_depotlive-v16`.`xmlconnect_notification_template`' as table,
  '`push_title` LIKE \'%1720%\'' as condition,
  count(*) as count
FROM `theprint_depotlive-v16`.`xmlconnect_notification_template`
WHERE `push_title` LIKE '%1720%'

UNION

...

WHERE count > 0;

如果您的查询列表位于表中或 mysql 可以读取的内容中,您可能会使用动态 SQL 以编程方式生成上述查询。

于 2012-08-31T22:41:15.713 回答