如何在mySql中搜索连续值

时间:2015-09-01 07:22:53

标签: mysql

我正在尝试在MySql中进行搜索,但无法弄清楚如何设置查询。我知道我的数据库设置有点混乱,但我现在坚持了。我想以任何方式搜索attrValue列并查找唯一字符串,在找到之后我想将其与10个连续(以下)结果一起显示。 在我的情况下,这甚至可能吗?

以下是我的尝试:

SELECT attrName, attrValue
FROM def_servpath_0001_weatherstation
JOIN (
SELECT *
FROM def_servpath_0001_weatherstation
WHERE attrValue = '8:0:0,1.9.2015'
)t
LIMIT 11

但我没有运气。有没有人有任何建议?

enter image description here

编辑1 我正在为表提供转储:

-- phpMyAdmin SQL Dump
-- version 4.0.10.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 01, 2015 at 10:07 AM
-- Server version: 5.1.73
-- PHP Version: 5.3.3

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `def_serv`
--

-- --------------------------------------------------------

--
-- Table structure for table `def_servpath_0001_weatherstation`
--

CREATE TABLE IF NOT EXISTS `def_servpath_0001_weatherstation` (
  `recvTimeTs` mediumtext,
  `recvTime` text,
  `entityId` text,
  `entityType` text,
  `attrName` text,
  `attrType` text,
  `attrValue` text,
  `attrMd` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `def_servpath_0001_weatherstation`
--



INSERT INTO `def_servpath_0001_weatherstation` (`recvTimeTs`, `recvTime`, `entityId`, `entityType`, `attrName`, `attrType`, `attrValue`, `attrMd`) VALUES
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'time', 'datetime', '6:30:0,1.9.2015', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'at', 'double', '18.799', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'ah', 'double', '91.0', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'ws', 'double', '0.01', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'wd', 'int', '270', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'sr', 'double', '17.181', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'sm1', 'double', '24.683', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'sp', 'double', '17.181', '[]'),
('1441083706', '2015-09-01T07:01:46.104', '0001', 'WeatherStation', 'bt', 'double', '6.552', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'time', 'datetime', '6:45:0,1.9.2015', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'at', 'double', '18.799', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'ah', 'double', '91.0', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'ws', 'double', '0.0', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'wd', 'int', '270', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'sr', 'double', '17.898', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'sm1', 'double', '24.683', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'sp', 'double', '17.898', '[]'),
('1441083713', '2015-09-01T07:01:53.549', '0001', 'WeatherStation', 'bt', 'double', '6.591', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'time', 'datetime', '7:0:0,1.9.2015', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'at', 'double', '19.400', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'ah', 'double', '91.0', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'ws', 'double', '0.0', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'wd', 'int', '270', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'sr', 'double', '18.488', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'sm1', 'double', '24.683', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'sp', 'double', '18.488', '[]'),
('1441083720', '2015-09-01T07:02:00.951', '0001', 'WeatherStation', 'bt', 'double', '6.640', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'time', 'datetime', '7:15:0,1.9.2015', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'at', 'double', '19.400', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'ah', 'double', '91.0', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'ws', 'double', '0.59', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'wd', 'int', '236', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'sr', 'double', '18.801', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'sp', 'double', '18.801', '[]'),
('1441087323', '2015-09-01T08:02:03.349', '0001', 'WeatherStation', 'bt', 'double', '6.689', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'time', 'datetime', '7:30:0,1.9.2015', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'at', 'double', '20.0', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'ah', 'double', '90.0', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'ws', 'double', '0.35', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'wd', 'int', '290', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'sr', 'double', '18.894', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'sm1', 'double', '24.683', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'sp', 'double', '18.894', '[]'),
('1441087330', '2015-09-01T08:02:10.383', '0001', 'WeatherStation', 'bt', 'double', '6.757', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'time', 'datetime', '7:45:0,1.9.2015', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'at', 'double', '20.5', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'ah', 'double', '90.0', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'ws', 'double', '0.37', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'wd', 'int', '322', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'sr', 'double', '19.298', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'sm1', 'double', '24.683', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'sp', 'double', '19.298', '[]'),
('1441087338', '2015-09-01T08:02:18.889', '0001', 'WeatherStation', 'bt', 'double', '6.865', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'time', 'datetime', '8:0:0,1.9.2015', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'at', 'double', '21.099', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'ah', 'double', '88.0', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'ws', 'double', '0.35', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'wd', 'int', '290', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'sr', 'double', '19.391', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'sp', 'double', '19.391', '[]'),
('1441087346', '2015-09-01T08:02:26.037', '0001', 'WeatherStation', 'bt', 'double', '6.923', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'time', 'datetime', '8:15:0,1.9.2015', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'at', 'double', '21.599', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'ah', 'double', '85.0', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'ws', 'double', '0.52', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'wd', 'int', '282', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'sr', 'double', '19.548', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'sp', 'double', '19.548', '[]'),
('1441090890', '2015-09-01T09:01:30.186', '0001', 'WeatherStation', 'bt', 'double', '6.962', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'time', 'datetime', '8:30:0,1.9.2015', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'at', 'double', '22.200', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'ah', 'double', '84.0', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'ws', 'double', '0.98', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'wd', 'int', '58', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'sr', 'double', '19.796', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'sp', 'double', '19.796', '[]'),
('1441090898', '2015-09-01T09:01:38.072', '0001', 'WeatherStation', 'bt', 'double', '7.011', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'time', 'datetime', '8:45:0,1.9.2015', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'at', 'double', '23.299', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'ah', 'double', '80.0', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'ws', 'double', '0.27', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'wd', 'int', '242', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'sr', 'double', '19.796', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'sp', 'double', '19.796', '[]'),
('1441090905', '2015-09-01T09:01:45.32', '0001', 'WeatherStation', 'bt', 'double', '7.118', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'time', 'datetime', '9:0:0,1.9.2015', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'at', 'double', '24.400', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'ah', 'double', '77.0', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'ws', 'double', '0.22', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'wd', 'int', '270', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'sr', 'double', '20.138', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'sp', 'double', '20.138', '[]'),
('1441090913', '2015-09-01T09:01:53.36', '0001', 'WeatherStation', 'bt', 'double', '7.060', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'time', 'datetime', '9:15:0,1.9.2015', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'at', 'double', '25.5', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'ah', 'double', '68.0', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'ws', 'double', '0.65', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'wd', 'int', '280', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'pp', 'double', '0.0', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'sr', 'double', '20.170', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'sm1', 'double', '24.386', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'lw1', 'double', '0.0', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'sp', 'double', '20.170', '[]'),
('1441094510', '2015-09-01T10:01:50.44', '0001', 'WeatherStation', 'bt', 'double', '7.050', '[]');

1 个答案:

答案 0 :(得分:1)

SELECT attrName, attrValue
FROM def_servpath_0001_weatherstation
WHERE attrValue = '8:0:0,1.9.2015'

UNION 

SELECT a.attrName, a.attrValue
FROM def_servpath_0001_weatherstation a
JOIN (
SELECT *
FROM def_servpath_0001_weatherstation
WHERE attrValue = '8:0:0,1.9.2015'
)b ON a.recvTimeTs=b.recvTimeTs AND a.attrValue <>'8:0:0,1.9.2015'
LIMIT 10