2013-08-07 81 views
0

嗨,我有以下查詢,但它仍然給我指定的結果,不給我。這不在什麼地方?mysql不在聲明中,不工作

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id from hierarchy left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn where taxonomic_units.rank_id = 220 and hierarchy.hierarchy_string LIKE '%180211%' and taxonomic_units.tsn not in ('180212') order by rand() limit 1 

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id from hierarchy left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn where taxonomic_units.rank_id = 220 and hierarchy.hierarchy_string LIKE '%180210%' and taxonomic_units.tsn not in ('180212,573165') order by rand() limit 1 

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id from hierarchy left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn where taxonomic_units.rank_id = 220 and hierarchy.hierarchy_string LIKE '%180130%' and taxonomic_units.tsn not in ('180212,573165,573165') order by rand() limit 1 

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id from hierarchy left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn where taxonomic_units.rank_id = 220 and hierarchy.hierarchy_string LIKE '%179913%' and taxonomic_units.tsn not in ('180212,573165,573165,585192') order by rand() limit 1 

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id from hierarchy left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn where taxonomic_units.rank_id = 220 and hierarchy.hierarchy_string LIKE '%158852%' and taxonomic_units.tsn not in ('180212,573165,573165,585192,624896') order by rand() limit 1 

這裏是重複的結果,我不是在聲明中假設過濾出來,但它沒有。

0 180212 
1 573165 
2 573165 
3 632899 
4 632141 
5 647171 

回答

0

使用此查詢:

select taxonomic_units.tsn, hierarchy.hierarchy_string, hierarchy.TSN, taxonomic_units.rank_id 
    from hierarchy 
     left join taxonomic_units on hierarchy.TSN = taxonomic_units.tsn 
     where taxonomic_units.rank_id = 220 
      and hierarchy.hierarchy_string LIKE '%158852%' 
      and taxonomic_units.tsn not in ('180212','573165','573165','585192','624896') 
     order by rand() limit 1 

您需要添加'的所有價值,因爲這些都是不同的值。而且你已經在開始時和結束時將其視爲單個字符串。

+0

他顯然不知道下一個號碼 –

+0

@YourCommonSense,但根據他的輸出,這應該是這樣的類型,所以這不是錯誤的。不需要downvote。 –

+0

我該如何在PHP中做到這一點?喜歡這個 ? 「'」。 implode(「','」,$ myArray)。 「'」; – user2604754