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

2021-10-05 11:41:45 字數 834 閱讀 5937

當我們使用mysq語句查詢某乙個字段(比如說金額)需要進行字段求和

或者是對於某乙個欄位去重操作

select

count

(distinct

(`social_credit_code`))

as businesstotal,

sum(

`settle_num`

)as persontotal

from

zhu_b_task_cycle

where

`id`

= $id

條件判斷

更新某乙個字段進行加·操作的時候,如果這個字段沒有預設值(null)的話,進行加一操作會失效,這個時候就要對他進行判斷,如果是null的話給他複製為0再加1(或者直接變成1也行)

update

`zhu_c_salary`

as a,

`zhu_b_task_cycle`

as b

set b.

`withdrawn_num`=if

(b.`withdrawn_num`

isnull,1

,`withdrawn_num`+1

),a.

`status`=

2,a.

`withdraw_time`

= ?where

a.`tel`

= ? and a.

`status`=

0and a.

`b_task_cycle_id`

= b.

`id`

mongodb去重語句詳解

db.demo.aggregate count dups foreach function doc 當前資料庫的demo集合呼叫aggregate方法 通過欄位text對資料進行分類 每類資料每有乙個計數加1並存入變數count中 將 id不重複的存入dups中 目前取出的每組資料只要count大於...

python基礎之 按規律加空格,去空格,去重

最近寫邏輯 用到字串列表較多,就回顧了下基礎,總結了加減空格的辦法 兩種辦法,推薦第二種 s abcdefghijklmnopqret def fen s,n b list s c for i in range n,len b int len b n,n 1 b.insert i,c join b ...

MySQL 資料查重 去重的實現語句

有乙個表user,字段分別有id nick name password email phone。一 單字段 nick name 查出所有有重覆記錄的所有記錄 select from user where nick name in select nick name from user group by...