gpt4 book ai didi

mysql - 如何在mySql中搜索连续值

转载 作者:行者123 更新时间:2023-11-29 12:01:21 25 4
gpt4 key购买 nike

我正在尝试在 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', '[]');

最佳答案

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

关于mysql - 如何在mySql中搜索连续值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32325818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com