0

100,000 rows in a table which contains a column that stores a large XML block, I need to check if there is a certain XML tag is filled with data in this column, lets say the column is called test_request and the XML tag is named 'd'. Also I want to make sure that the value inside 'd' doesn't contain a newline /n within the XML tag. So for every row that has a match I want to add 1 to a overall count. Here is my query so far.

SELECT EXTRACTVALUE( UNCOMPRESS(`test__request` ) ,  count('/a/b/c/d') ) 
FROM testTable16
WHERE  `test_created` >  '2014-08-16 10:00:00'
AND  `test_created` <=  '2014-08-16 10:10:00'
AND  `test_client` =  'test2'
AND  `test_user` =  'testuser2'
AND UNCOMPRESS(  `test__request` ) LIKE  '%<testID>test</testID>%'
LIMIT 0 , 30

it doesn't work though as it returns 100,000 rows which I cant obviously sift through. And I am not sure how to do the isnt newline check.

4

1 回答 1

1

如果您只返回带有计数的行,则应将计数移至WHERE子句。

我的 XPATH 有点生疏,但我相信您可以使用带有 contains 函数的谓词:

SELECT *
FROM testTable16
WHERE  `test_created` >  '2014-08-16 10:00:00'
AND  `test_created` <=  '2014-08-16 10:10:00'
AND  `test_client` =  'test2'
AND  `test_user` =  'testuser2'
AND UNCOMPRESS(`test__request`) LIKE  '%<testID>test</testID>%'
AND EXTRACTVALUE( 
      UNCOMPRESS(`test__request`),  
      'count(/a/b/c/d[contains(text(),"\n")])'
    ) > 0
LIMIT 0 , 30

如果要返回至少具有一个匹配项的所有行的计数,请使用SELECT COUNT(*) ...

如果您想要所有节点计数的总数,请使用:

SELECT SUM(EXTRACTVALUE( 
         UNCOMPRESS(`test__request`),  
         'count(/a/b/c/d[contains(text(),"\n")])'
       ))
FROM testTable16
WHERE  `test_created` >  '2014-08-16 10:00:00'
AND  `test_created` <=  '2014-08-16 10:10:00'
AND  `test_client` =  'test2'
AND  `test_user` =  'testuser2'
AND UNCOMPRESS(`test__request`) LIKE '%<testID>test</testID>%'
于 2014-08-18T14:41:39.267 回答