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

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 に答える