比较两个MySQL表之间的最高值(Compare Highest Values Between Two MySQL Tables)
我有两个表search_history和parse_history,它们包含具有不同时间戳的相同案例编号的多行,当我最后一次刮时,在另一个表中,当我上次解析它时。 我试图编写一个查询,它将比较search_history表中案例编号的最高时间戳值与parse_history表中该案例编号的最高时间戳值。 如果search_history中该病例号的最近条目的时间戳高于parse_history表中该病例号的最近条目,则返回该时间戳。
到目前为止我看到的所有示例都是使用Max或groupwise max从单个表中的多个条目中获取最高值。 比较两者我找不到任何东西。
下面是我的两个表格,在下面的示例中,我需要返回案例编号4W90B2F,因为最新的search_history条目的时间戳比该案例编号的最新parse_history条目更高。
search_history Table ID CaseNumber TimeStamp 1 4W90B2F 2017-09-30 00:25:33 2 0DB0NGV 2017-09-30 00:15:35 3 4W90B2F 2017-10-05 00:15:44 4 0DB0NGV 2017-10-10 00:53:13 5 4W90B2F 2017-10-20 00:25:34 parse_history Table ID CaseNumber TimeStamp 1 4W90B2F 2017-10-01 00:25:33 2 0DB0NGV 2017-10-02 00:15:35 3 4W90B2F 2017-10-06 00:15:44 4 0DB0NGV 2017-10-11 00:53:13
SQL Fiddle链接以示例http://sqlfiddle.com/#!9/bc229f
我的尝试到目前为止已经过了
SELECT sh.* FROM search_history sh LEFT JOIN search_history b ON sh.CaseNumber = b.CaseNumber AND sh.Timestamp < b.Timestamp INNER JOIN parse_history as ph LEFT JOIN parse_history c ON ph.CaseNumber = c.CaseNumber AND ph.Timestamp < c.Timestamp WHERE b.CaseNumber IS NULL AND c.CaseNumber IS NULL LIMIT 50
I have two tables, search_history and parse_history, that contain multiple rows of the same case number with different timestamps of when I last scraped it and in the other table when I last parsed it. I'm trying to write a query that will compare the highest timestamp value for a case number in the search_history table with the highest timestamp value for that case number in the parse_history table. If the timestamp for the most recent entry for that case number in search_history is higher than the most recent entry for that case number in the parse_history table then it is returned.
All the examples I've seen so far are for getting the highest values from multiple entries out of a single table using Max or groupwise max. I can't find anything on comparing the two.
Below are my two tables and in the example below I would need case number 4W90B2F to be returned since the most recent search_history entry has a higher timestamp than the most recent parse_history entry for that case number.
search_history Table ID CaseNumber TimeStamp 1 4W90B2F 2017-09-30 00:25:33 2 0DB0NGV 2017-09-30 00:15:35 3 4W90B2F 2017-10-05 00:15:44 4 0DB0NGV 2017-10-10 00:53:13 5 4W90B2F 2017-10-20 00:25:34 parse_history Table ID CaseNumber TimeStamp 1 4W90B2F 2017-10-01 00:25:33 2 0DB0NGV 2017-10-02 00:15:35 3 4W90B2F 2017-10-06 00:15:44 4 0DB0NGV 2017-10-11 00:53:13
SQL Fiddle Link to sample http://sqlfiddle.com/#!9/bc229f
My attempt so far times out
SELECT sh.* FROM search_history sh LEFT JOIN search_history b ON sh.CaseNumber = b.CaseNumber AND sh.Timestamp < b.Timestamp INNER JOIN parse_history as ph LEFT JOIN parse_history c ON ph.CaseNumber = c.CaseNumber AND ph.Timestamp < c.Timestamp WHERE b.CaseNumber IS NULL AND c.CaseNumber IS NULL LIMIT 50
原文:https://stackoverflow.com/questions/46976667
最满意答案
getElementsByClassName
返回一个HTMLCollection ,所以为了访问这个集合中第一个找到的元素,你需要使用[0]
索引:var tes_val = tes[0].value;
但是,这是使用API的笨拙方式。 如果您只对类
a_b_1
的第一个元素感兴趣,a_b_1
使用Document.querySelector方法:var tes = document.querySelector('.a_b_1'); var tes_val = tes.value; console.log(tes_val);
getElementsByClassName
returns an HTMLCollection, so in order to access first found element in this collection you need to use[0]
index:var tes_val = tes[0].value;
However, this is clumsy way to use API. If you are only interested in the first element with class
a_b_1
use Document.querySelector method:var tes = document.querySelector('.a_b_1'); var tes_val = tes.value; console.log(tes_val);
相关问答
更多-
这不是一个文件的方法: function getElementsByClassName(node, classname) { var a = []; var re = new RegExp('(^| )'+classname+'( |$)'); var els = node.getElementsByTagName("*"); for(var i=0,j=els.length; i我的症状错了。 它实际上是phantomjs中不存在的.click()函数。 Object.keys(document.getElementsByClassName('video')[0])返回数据,即使console.log为空。 我通过使用解决了这个问题 function click(el){ var ev = document.createEvent("MouseEvent"); ev.initMouseEvent( "click", true /* bubbl ...
javascript document.getElementsbyClassName不是函数(javascript document.getElementsbyClassName is not a function)[2023-07-22]
应该是document.getElementsByClassName (“B”是区别) Should be document.getElementsByClassName (the "B" is the difference)document.getElementsByClassName与类完全匹配(document.getElementsByClassName exact match to class)[2024-01-07]
classname item one表示元素具有类item和类one 。 因此,当您执行document.getElementsByClassName('item') ,它也会返回该元素。 您应该执行以下操作来选择仅包含类item的元素: e = document.getElementsByClassName('item'); for(var i = 0; i < e.length; i++) { // Only if there is only single class if(e[i].c ...document.getElementsByClassName()数组中元素的顺序(Order of elements in document.getElementsByClassName() array)[2023-01-30]
是的,在符合实现的过程中,您将会返回不是数组,而是HTMLCollection 。 结果将以文档顺序 (自顶向下,深度优先遍历 - 这是一种奇特的说法,看看标记时的样子:-))。 例如,对于这个文件:您很可能在类container的元素存在之前运行该代码。 你的jQuery可能工作,因为你有它在一个$(document).ready回调( $( function( ) { ...是一个常见的方式来做到这一点)。 要么将非jQuery代码添加到window.onload事件处理程序中,要么只需将HTML中的脚本移动到比您希望选择的元素更低的位置。 在关闭之前