2012-01-20 82 views
3

我需要在客戶端完全構建一個Twitter模塊。是否可以在YQL中獲得兩個結果集的交集或差異?

我打算使用Twitter API作爲數據,YQL得到Same Origin Policy,並且也因爲它的更高速率限制。我之前使用過這種組合,取得了成功。

我需要做的一件事就是獲得帶有hashtag和來自有限用戶集的推文列表。

This gets tweets with the #stackoverflow hash tag by users alexdickson and lizardbill.

我還需要得到不同的鳴叫。

This gets all tweets with the #stackoverflow hash tag.

現在,我需要顯示第二集合,但不包括從第一組的結果。這將是一個diff的結果,如PHP的array_diff()

爲了完整起見,我可能還需要通過獲得兩個結果的交集,即兩個結果集中出現的tweets列表來實現某些功能。這與PHP的array_intersect()類似。

自從我使用SQL並且無法想象如何在YQL中實現這一點,這已經有一段時間了。

回答

2

YQL支持子選擇(子查詢)。請參閱Joining Tables with Sub-selects。子選擇與IN operator一起使用,以過濾外部選擇的結果。

爲了您的特定查詢,也有twitter.searchCommunity Open Data Table可以救你從建築Twitter的網址,並使用json表。

select * 
from twitter.search 
where q="#stackoverflow" 
and id not in (
    select id 
    from twitter.search 
    where q="#stackoverflow from:alexdickson, OR from:lizardbill" 
) 

Try this query in the YQL console

2

看起來像我終於明白了。 YQL支持子查詢。

SELECT results 
FROM json 
WHERE url = "http://search.twitter.com/search.json?q=%23stackoverflow" 
     AND results.id NOT IN (SELECT results.id 
           FROM json 
           WHERE url = 
"http://search.twitter.com/search.json?q=%23stackoverflow%20from%3aalexdickson,%20OR%20from%3alizardbill" 
) 

YQL Console

+0

你也可以做類似的方式使用'twitter.search'社區表。 'select * from twitter.search where q =「#stackoverflow」and id not in(從twitter.search選擇id,其中q =「#stackoverflow from:alexdickson或OR from:lizardbill」) – salathe

+0

@salathe謝謝你。我從未注意到社區表。如果你張貼作爲答案,我會接受:) – alex

+0

沒問題。 [答案](http://stackoverflow.com/a/8972440/113938)。 – salathe

相關問題