道歉已经发布。
在谷歌搜索了很多,但我不明白如何在MySQL Query中使用DECLARE语法。 我不是MySQL专家。我在互联网上看到这些代码用于DECLARE语法。在任何地方都没有看到完整的查询。
DECLARE @destlist varchar(max)
SET @destlist = SELECT destinations FROM tbl_rings_to_groups WHERE id = '1' AND user_id = '1'
SELECT count( id ) AS totalDestination, group_concat( ring_to_number ) AS phoneNumbers
FROM tbl_destinations
WHERE id IN (CONCAT('SELECT ', REPLACE(@destlist), ',', ' UNION ALL SELECT '))
我将此用于获取结果。
$result = $db->query("select from
table where something =
somethingElse order by something");
现在,如何在上面的代码中使用DECLARE
。
我试过这个。
$result = $db->query(" DECLARE @destlist varchar(max)
SET @destlist = SELECT destinations FROM tbl_rings_to_groups WHERE id = '1' AND user_id = '1'
SELECT count( id ) AS totalDestination, group_concat( ring_to_number ) AS phoneNumbers
FROM tbl_destinations
WHERE id IN (CONCAT('SELECT ', REPLACE(@destlist), ',', ' UNION ALL SELECT '))");
这是使用MySQL DECLARE
的正确方法吗?