對字串鍵索引DISTINCT的使用

2021-09-09 08:42:11 字數 739 閱讀 5939

會列出所有不同的手機號(account)

select distinct account from user

會列出所有不同的手機號(account)個數

select count(distinct account) as l from use

會列出以手機號前兩位做索引,索引的個數

select count(distinct left(account,2)) as l from `user`

以手機號做索引

alter table user add index index1(account)

以手機號前6位做索引

alter table user add index index1(account(6))

像身份證這種前面字串重複率大的  可以選擇倒序儲存

select field_list from t where id_card = reverse('input_id_card_string')

或者用hash欄位(既在表裡新增乙個字段儲存hash值,並對其建立索引,插入或者查詢的時候利用crc32()這個函式)

要注意hash衝突 所以查詢條件加上and id_card='input_id_card_string'

mysql> select field_list from t where id_card_crc=crc32('input_id_card_string') and id_card='input_id_card_string'

1065 字串的索引對

題目描述 給出 字串 text 和 字串列表 words,返回所有的索引對 i,j 使得在索引對範圍內的子字串 text i text j 包括 i 和 j 屬於字串列表 words。示例 1 輸入 text thestoryofleetcodeandme words story fleet lee...

對串 旋轉字串

題目 旋轉字串 對串 描述s 0.n 1 是乙個長度為n的字串,定義旋轉函式left s s 1 n 1 s 0 比如s abcd left s bcda 乙個串是對串當且僅當這個串長度為偶數,前半段和後半段一樣。比如 abcabc 是對串,aabbcc 則不是。現在給你字串,判斷他是否可以由乙個對...

對字串切片

字串 和 unicode字串 u 也可以看成是一種list,每個元素就是乙個字元。因此,字串也可以用切片操作,只是操作結果仍是字串 abcdefg 3 abc abcdefg 3 efg abcdefg 2 aceg 在很多程式語言中,針對字串提供了很多各種擷取函式,其實目的就是對字串切片。pyth...