mysql搜尋結果去重 MySQL去除查詢結果重複

2021-10-13 10:36:57 字數 952 閱讀 7147

出現結果重複數sql(四表關聯):

select

count(post.id )

from wp_posts as post left join

wp_term_relationships as relation

on(post.menu_order =

relation.term_order) left join wp_term_taxonomy

as taxonomy

on(relation.term_taxonomy_id = taxonomy.term_id) left join

wp_terms as

term on(taxonomy.term_id = term.term_id)

正常的結果應該顯示490條資料,但是結果顯示了224941。

解決這個辦法是在對應的count()裡面加上distinct

distinct這個關鍵字主要用於過濾掉多餘的重覆記錄只保留一條,但往往只用它來返回不重覆記錄的條數,而不是用它來返回不重記錄的所有值。

注意:它有侷限性,比如吧不能對應多個目標字段,只能對應乙個目標字段。

解決重複結果書的sql如下:

select

count(distinct post.id)

from wp_posts as post left join

wp_term_relationships as relation

on(post.menu_order =

relation.term_order) left join wp_term_taxonomy

as taxonomy

on(relation.term_taxonomy_id = taxonomy.term_id) left join

wp_terms as

term on(taxonomy.term_id = term.term_id)

搜尋結果去重 知乎搜尋評測實踐

效果評測一直是軟體測試中令人頭疼的部分,因為很多情況下效果的好壞是乙個偏主觀的東西,如何經過抽樣 對比 打分 使用者資料等客觀的方式來評價一款產品的好壞,是我們測試工程師值得思考的問題。隨著知乎 dau 的持續增長,知乎搜尋也成了乙個重要的流量分發的入口。知乎搜尋對質量的要求也越來越高,於是效果評測...

mysql 對查詢到的結果進行去重

於是我改動了一下sql select distinct sd1.ship address name,a1.ship address id,group concat a1.ship date b1.lot number,a1.company id from outstock so headers a1...

mysq語句求和,去重,加一操作

當我們使用mysq語句查詢某乙個字段 比如說金額 需要進行字段求和 或者是對於某乙個欄位去重操作 select count distinct social credit code as businesstotal,sum settle num as persontotal from zhu b ta...