我有两个SQL表:
PROPERTY
PID Address
1 123 Center Road
2 23 North Road
3 3a/34 Crest Avenue
5 49 Large Road
6 2 Kingston Way
7 4/232 Center Road
8 2/19 Ash Grove
9 54 Vintage Street
10 15 Charming Street
PROPERTY_FEATURE
P.PID Feature
1 Wine Cellar
1 Helipad
2 Tennis Court
2 Showroom
7 Swimming Pool - Above Ground
9 Swimming Pool - Below Ground
9 Wine Cellar
我想选择包含特定功能的属性。例如,我想选择具有Wine Cellar和Helipad功能的属性ID,它将返回ID为1的Property。
有什么想法吗?
答案 0 :(得分:2)
您可以使用WebElement contextNode=driver.findElement(By.xpath("/html/body"));
if(driver instanceof JavascriptExecutor) {
String jswalker=
"var tw = document.createTreeWalker("
+ "arguments[0],"
+ "NodeFilter.SHOW_TEXT,"
+ "{ acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT;} },"
+ "false"
+ ");"
+ "var ret=null;"
// skip over the number of text nodes indicated by the arguments[1]
+ "var skip;"
+ "for(skip=0; tw.nextNode() && skip<arguments[1]; skip++);"
+ "if(skip==arguments[1]) { " // found before tw.nextNode() ran out
+ "ret=tw.currentNode.wholeText.trim();"
+ "}"
+ "return ret;"
;
int textNodeIndex=3; // there will be empty text nodes before after <b>
Object val=((JavascriptExecutor) driver).executeScript(
jswalker, contextNode, textNodeIndex
);
String textThatINeed=(null!=val ? val.toString() : null);
}
和Group By
子句
Having
1)select PID
From PROPERTY_FEATURE
Group by PID
Having COUNT(case when Feature = 'Wine Cellar' then 1 end) > 0 --1
and COUNT(case when Feature = 'Helipad' then 1 end) > 0 -- 2
仅在Counts
&amp; Feature = 'Wine Cellar'
会确保每个> 0
'Wine Cellar'
2)PID
仅在Counts
&amp; Feature = 'Helipad'
会确保每个> 0
'Helipad'
PID
将确保1&amp; 2满足然后返回AND
答案 1 :(得分:0)
您可以通过过滤所需的功能,然后在HAVING子句中进行分组和计数来完成此操作。您也可以直接分组(不先过滤),但如果表格非常大,有很多pid,那么将导致大量不必要的行分组,最终不会使用。
这样的事情:
select pid
from property_feature
where feature in ('Wine Cellar', 'Helipad')
group by pid
having count(feature) = 2;
这假设表格中没有重复项(因此您不能两次1 'Helipad'
,弄乱计数)。如果可以重复,请将最后一行更改为count (distinct feature) = 2
。