mysql查詢結果中,有多條不同資料但其中多個欄位值會相同的

2021-03-22 19:03:47 字數 3880 閱讀 6939

1樓:oo剛仔

select max(id),elec_id,model_info_id from 表 group by elec_id,model_info_id

2樓:喬克叔叔嗨

可能寫的有點複雜,但是結果應該是沒問題的,自己也剛好需要查這種情況的資料

select * from

(select elec_id,model_info_id,max(add_date) add_date from 主表 group by

elec_id,model_info_id) t1left join

主表 t2

on t1.elec_id=t2.elec_id and t1.model_info_id=t2.model_info_id and t1.add_date=

t2.add_date;

mysql查詢結果中有多條重複記錄只保留一條

3樓:匿名使用者

這個需要分情況。 1,你的資料庫表中有主鍵,且主鍵上面的資料為唯一值。也就是沒有重複值。 那麼你在刪除的時候,將這個唯一值作為條件進行刪除。

4樓:匿名使用者

如果是完全重複的話可以用distinct關鍵字去重。

mysql表裡有多條記錄,把這個這裡的某個欄位其中一條記錄值更新為1,其他為0 5

5樓:匿名使用者

update vcos_wifi_config set config_state=case config_id when '$value' then 1 else 0 end

mysql如何查詢select出兩個結構相同的表中,兩個欄位只要有一項不同的記錄?我下面這樣寫為什麼不行?

6樓:

查詢t_demodata表:

select t_demodata.* from t_demodata where exists (select 1 from temp_demodata where temp_demodata.date <> t_demodata.

date or temp_demodata.time <> t_demodata.time)

查詢temp_demodata 表:

select temp_demodata .* from temp_demodata where exists (select 1 from t_demodata where temp_demodata.date <> t_demodata.

date or temp_demodata.time <> t_demodata.time)

兩張表都需要就直接union下:

select t_demodata.* from t_demodata where exists (select 1 from temp_demodata where temp_demodata.date <> t_demodata.

date or temp_demodata.time <> t_demodata.time)

union

select temp_demodata .* from temp_demodata where exists (select 1 from t_demodata where temp_demodata.date <> t_demodata.

date or temp_demodata.time <> t_demodata.time)

mysql如何同時查詢一個欄位的兩個不同值的資料的最後一條資料

7樓:匿名使用者

--第一種寫法

select * from 表名 where deveui='3430363057376506' or deveui='3430363064378607'

--第二種寫法

select * from 表名 where deveui in('3430363057376506','3430363064378607')

在mysql資料庫中如何讓某個欄位有重複的只取一條

8樓:魚尾摯愛白菜

select *

from table  ###

where not exists (

select * from table  ###where # = #

and ## < ##

)在使用mysql時,有時需要查詢出某個欄位不重複的記錄,雖然mysql提供 有distinct這個關鍵字來過濾掉多餘的重複記錄只保留一條,但往往只用它來返回不重複記錄的條數,而不是用它來返回不重記錄的所有值。其原因是 distinct只能返回它的目標欄位,而無法返回其它欄位,這個問題讓我困擾了很久,用distinct不能解決的話,只有用二重迴圈查詢來解決。

給個例子把,比如:表table_a 4條資料id a b c d

01 ab 1a2 1b2 121

02 ab 2a3 3b3 4a1

03 ac 1a2 1b2 121

04 ac 2a4 3b2 52g

何讓a欄位重複取條 比

01 ab 1a2 1b2 121

03 ac 1a2 1b2 121

保留相同a值id行

select *

from table_a a

where not exists (

select 1 from table_a bwhere b.a = a.a

and b.id < a.id)

9樓:匿名使用者

select max(id) as id,fid,title,date from table group by fid,title,date

10樓:尋_常

select * from (select * from a order by id desc) as b group by fid

mysql查詢資料 有6條 如果前4條資料是重複資料,我只想顯示一條,後面的資料該怎麼顯示怎麼顯示

11樓:匿名使用者

樓主指的重複資料是指alias1這個欄位是重複的嗎?

在mysql資料庫中存有多個相同的記錄,如何實現--查詢到所有相同的第一條記錄之後就返回?

12樓:匿名使用者

select distinct * from tablesql中可以這樣 不知道mysql可以不!

13樓:匿名使用者

使用distinct可以過濾重複的資料。select distinct username,password from user where username="lin" and password="111"試試看吧。我經

常用。。。

mysql中提取一條很多欄位的記錄只改變一個或兩個欄位從新寫一條新記錄有什麼樣便捷的辦法

14樓:匿名使用者

假如我的表這樣設定的

表名:aa

id key auto_incrementdata1 varchar(255)

data2 varchar(255)

那麼要達到

你要的效果,可以這樣做

replace into aa(data1,data2) select data1,***x from aa [where id in y]

說明:***x是你要更改的欄位資料

後面的where是選擇你要改幾個記錄

15樓:匿名使用者

碉堡了都········

mysql分頁問題,mysql分頁查詢問題

因為card表總共有11條記錄,count 出來就是11了count是針對符合where條件的記錄進行的,是不考慮limit的如果想計算select from table where.limit 0,10返回多少條記錄,需要這樣寫 select count from select from tabl...

MySql怎麼查詢前10條資料mysql如何查詢各年的前10條記錄

mysql沒有select top的語法,你得用用limit select from 表名 limit m,n 從m開始,取n條 select from 你的表名 order by 你的欄位 limit 10select from 你的表名 order by 你的欄位 limit 10select ...

MYSQL查詢DATE FORMAT是否會影響查詢速度?有沒有別的方式代替

mysql select something from tablewhere to days now to days date col 30 dayofweek date 返回日期date的星期索引 1 星期天,2 星期一,7 星期六 這些索引值對應於odbc標準。後臺處理 format 或者用su...