在MySQL中指定分区名称时如何从分区中进行选择

在MySQL中指定分区名称时如何从分区中进行选择,mysql,sql,select,partition,Mysql,Sql,Select,Partition,我也有这样的问题: 但是在Mysql中 使用时: select concat('p', year(now()), month(now())); 答复是: +----------------------------------------+ | concat('p', year(now()), month(now())) | +----------------------------------------+ | p20153 |

我也有这样的问题: 但是在Mysql中

使用时:

select concat('p', year(now()), month(now()));
答复是:

+----------------------------------------+
| concat('p', year(now()), month(now())) |
+----------------------------------------+
| p20153                                 |
+----------------------------------------+
尝试使用时:

select max(ttime) from table partition(select concat('p', year(now()), month(now()))));
我得到一个错误:

ERROR 1064 (42000): 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 'select concat('p', year(now()), month(now()))))' at line 1
当然,在尝试从表分区中选择maxttime时,P20153会按预期工作:

root@localhost [tom]> select max(ttime) from table partition(p20153);
+---------------------+
| max(ttime)          |
+---------------------+
| 2015-03-16 09:54:34 |
+---------------------+
1 row in set (0.00 sec)
注意,动态部分是分区名,而不是表名。 样本数据:

root@localhost [tom]> select id, ttime, value from table partition(p20153) limit 10;
+----------+---------------------+----------+
| id       | ttime               | value    |
+----------+---------------------+----------+
| 13964275 | 2015-03-01 00:05:11 | 16450824 |
| 13964291 | 2015-03-01 00:08:12 | 15964352 |
| 13964332 | 2015-03-01 00:09:42 | 14701984 |
| 13964379 | 2015-03-01 00:13:27 |    26128 |
| 13964411 | 2015-03-01 00:16:29 | 11073744 |
| 13964452 | 2015-03-01 00:20:34 | 14747992 |
| 13964486 | 2015-03-01 00:23:35 |   177800 |
| 13964507 | 2015-03-01 00:26:36 | 16786408 |
| 13964542 | 2015-03-01 00:28:28 |  8749552 |
| 13964571 | 2015-03-01 00:31:30 | 16932344 |
+----------+---------------------+----------+
10 rows in set (0.00 sec)

您在查询中使用的语法不正确请尝试以下操作

select max(ttime) from 
(
  select concat('p', year(now()), month(now())) as ttime 
)
temp 

请编辑您的问题并添加预期的输出以及示例数据不确定此查询有何帮助,因为ttime将获取分区名称,我只选择一个值中的最大值。我想我误导了你,我在问题中添加了样本数据和预期结果。