mysql導資料庫用到的語句

神馬和浮雲發表於2013-11-02

將欄位格式為2013-08-09 13:22:55轉換為時間戳

UPDATE `AttendClass` SET `regdate` = unix_timestamp(regDate2) WHERE `rowid` = 118280;

 

將欄位name前面新增一個字元x

update aa set name=concat('x',name)

 

MYSQL查詢重複記錄的方法

1、查詢表中多餘的重複記錄,重複記錄是根據單個欄位(peopleId)來判斷

select * from people   where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 

 2、刪除表中多餘的重複記錄,重複記錄是根據單個欄位(peopleId)來判斷,只留有rowid最小的記錄

delete from people   
where peopleId in (select peopleId from people group by peopleId   having count(peopleId) > 1)   
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)

 3、查詢表中多餘的重複記錄(多個欄位)

select * from vitae a   
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

 4、刪除表中多餘的重複記錄(多個欄位),只留有rowid最小的記錄

delete from vitae a   
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)   
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

 5、查詢表中多餘的重複記錄(多個欄位),不包含rowid最小的記錄

select * from vitae a   
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)   
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1) 

 

相關文章