[英]select a range from multiple tables named by date
The tables have the same structure and are named like (year and month attached): 这些表具有相同的结构,并命名为(附有年份和月份):
- tb_201302
- tb_201303
- tb_201304
Each table has a field date_insert
that contains the exact insert time in timestamp. 每个表都有一个字段
date_insert
,其中包含时间戳记中的确切插入时间。
Question: I want to be able to do a selection from those multiple tables, something like (in pseudo code): 问题:我希望能够从多个表中进行选择,例如(使用伪代码):
SELECT * FROM tb_201302, tb_201303 WHERE date_insert > '02/15' and date_insert < '03/25'
'02/05' and '03/25' would be timestamps normally
'02 / 05'和'03 / 25'通常是时间戳记
So it's basically selectin a range in multiple tables. 因此,它基本上是在多个表中选择一个范围。
I also tried using UNION 我也尝试使用UNION
SELECT * FROM (
(SELECT * FROM tb_201302 WHERE date_insert > '02/15' and date_insert < '03/25')
UNION
(SELECT * FROM tb_201303 WHERE date_insert > '02/15' and date_insert < '03/25')
) results
But I'm getting a syntax error, unexpected '(', expecting SELECT near '(SELECT * FROM tb_201202
但是我遇到
syntax error, unexpected '(', expecting SELECT near '(SELECT * FROM tb_201202
Any ideas ? 有任何想法吗 ?
Assumning this really is a SphinxQL question (the error message appears to be a Sphinx produced NOT a MySQL produced error)... 假设这确实是一个SphinxQL问题(错误消息似乎是Sphinx产生的,而不是 MySQL产生的错误)...
Your first attempt is right, just that you need to convert the actual timestamp, to be a numberic. 您的第一次尝试是正确的,只是您需要将实际时间戳转换为数字。 Can use
UNIX_TIMESTAMP()
in creating your index, so that the sphinx attribute contains a unix timestamp. 可以在创建索引时使用
UNIX_TIMESTAMP()
,以便sphinx属性包含unix时间戳。
Can then convert it to the same numeric 然后可以将其转换为相同的数字
SphinxQL> SELECT * FROM tb_201302, tb_201303
WHERE date_insert > 1360886400 AND date_insert < 1364169600
( strtotim()
in PHP can be used to get a timestamp from a date string) (PHP中的
strtotim()
可用于从日期字符串获取时间戳)
SELECT * FROM (
SELECT * FROM tb_201302 WHERE date_insert > '02/15' and date_insert < '03/25'
UNION
SELECT * FROM tb_201303 WHERE date_insert > '02/15' and date_insert < '03/25'
) results
Try this 尝试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.