English 中文(简体)
通过储存程序创建具有动态名称的表格
原标题:Create Tables with Dynamic Names via Stored Procedure

我正试图制作充满活力的表格。 我正在从这部法典中看到错误,这是一部动态的飞跃。 我不知道这个问题是什么。 我是动态和储存程序的新鲜事。

    PREPARE stmt FROM "CREATE TABLE `?` SELECT lat, lon, nfldtime FROM position_reports where mmsi = ? ORDER BY id DESC LIMIT 100";    

    EXECUTE stmt USING CONCAT("mmis", FORMAT(vesselID,0)), vesselID;

我在努力制定程序时,先是:

Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near CONCAT("mmis", FORMAT(vesselID,0)), vesselID;

I tried this:

EDIT:

从@Konerak的答复来看,现在的工作是:

set @s = CONCAT("CREATE TABLE mmsi", vesselID, " SELECT lat, lon, nfldtime FROM position_reports where mmsi = ", vesselID, " ORDER BY id DESC LIMIT 100");
prepare createTable from @s;
EXECUTE createTable;
DEALLOCATE PREPARE createTable;
最佳回答

http://strong>can t在一份准备声明上用替换一个表格名称,然后由执行者插入表格名称。

动态表格名称通常为badismo:最好在一张大张桌上加一栏“虚拟表格名称”。

如果你确实需要动态表格,你就不得不将表格名称输入PREPARE。 本身。

Pro s and con s of dynamic table names

Suppose that instead of putting all users inside one table, users with columns ID, Name, e-mail, country, ..., you put them into dynamic tables, users_country, with columns ID, Name, e-mail, ...

  • 各位可以很容易地询问所有表格。 你们想要知道你们的使用者中有多少是男性——你们不得不对每个桌子提出质询,而联合国也想到结果。 速度更快。

  • 您可以利用部分内容对表格进行实际区分,但您的逻辑观点仍然相同。 您认为,你使用适当表格的任何好处通常可以采用另一种方法实现。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...