1樓:匿名使用者
select a.sn,a.createdate,max(a.dayuse) from tab group by a.sn,a.createdate
標準的group by應用,前面的id應該是你自己隨便定義的吧,自己想辦法處理吧。
2樓:木_葉_兒
mysql環境下:
set @rank:=0;
set @ci:=null;
select id,sn,createdate,dayuse from
select id,sn,createdate,dayuse,rank from(select id,sn,createdate,dayuse,@rank:=if(@ci=createdate,@rank+1,1) as rank,@ci:=createdate from table_a
order by sn,createdate,dayuse desc) as t1
) awhere rank=1;
原答案:
sql server環境下:
select id,sn,createdate,dayuse from
select id,sn,createdate,dayuse,
row_number() over(partition by sn,createdate order by dayuse desc) as rownum
from table1
) awhere rownum=1
求sql語句 合併重覆記錄,並累加其中乙個欄位的值
3樓:匿名使用者
分組合併就成啊
select col1
,col2
,sum(value) as amountfrom tablex
group by col1, col2
4樓:啦就虧了
select sum(*) as 字段值的和 from table group by 重複字段
求sql語句,只修改重複資料中的一條記錄
5樓:匿名使用者
用檢視就可以啊
create view v1(
a,b,c,d) as
select a,b,c,row_number() over(partition by a,b,c order by a) as d
from 表名
update v1 set a='新值a',b='新值b',c='新值c' where d='1'
--這樣就完全能滿足你的要求 我測試過了,更新檢視就完全可以了,樓主可以試試
6樓:突擊手覓患
資料庫 ms sql2005下,
如果資料不重複的就不修改,則如下
with aa as
(select row_number() over(partition by a,b,c order by a,b,c) as rn,* from 表)
update aa set a=...
where rn=2
如果不管是否重複
with aa as
(select row_number() over(partition by a,b,c order by a,b,c) as rn,* from 表)
update aa set a=...
where rn=1
sql語句查詢 如何刪除重複多餘的資料
7樓:匿名使用者
這個是sql中distinct的典型用法:
1)從字面意思就可以了解到:
distinct [dis'tiŋkt] adj. 明顯的;獨特的;清楚的;有區別的
2)在sql中用distinct來消除重複出現的字段值。
使得每個字段值只出現一次。
具體用法如下:
select distinct 欄位名 from 表;
distinct 欄位名 意思就是只顯示一次該欄位名一般情況下和order by 結合使用,這樣可以提高效率。
所以這個問題的答案是:select distinct 1,2,3,4 from 表;
1,2,3,4分別代表第一,二,三,四列的欄位名,我猜測可能第一列就是每個人的id,
這樣你把重複的id過濾留下乙個,估計就是你想要的結果了。
希望我的回答能讓您滿意。
8樓:匿名使用者
delete from 表名 where 列名 not in "2012050111"。可以把2012050111以外都刪除。
9樓:匿名使用者
delete from table t where rowid not in (select max(rowid) from table t group by col1,col2,col3,col4,...)
把重複的列名分一下組,每組中只保留rowid最大的那條。
10樓:匿名使用者
select distinct +欄位+from+表名+條件
11樓:匿名使用者
delete from table where 欄位2=(select max(欄位2) from table group by 欄位1,欄位3,欄位4)
sql語句怎樣查詢並刪除單個欄位下的所有重複值, 重複的記錄只保留乙個
12樓:張愛民_浦東
需要乙個主鍵 id
如果是要刪除是姓名重複的話,試試以下**
delete ta where id not in
( select max(id) from group by nch )
如果要顯示不重複項的資料
select * from ta where id in
( select max(id) from group by 姓名 )
如果 nch 這個地段,你需要不重複 , 事實上就可以把這一列作為主鍵
另外,你在新增資訊的時候,做下判斷,如果該列中已有,就不執行新增的**。
並做提示資訊。
13樓:
受教了,我也正好遇到這個問題
求sql語句 資料庫中,想實現刪除重複資料,以時間為條件,保留最新的資料,其餘舊的資料都刪除?
14樓:湧銳達
人不可有傲氣,但不可無傲骨
sql中如何取重複的資料取時間最近的一條?
15樓:茶菊花
比如你資料庫中有乙個表tab(姓名name,登陸時間logtime)姓名有重複的名叫a
select top 1 * from tab where name='a' order by logtime desc
16樓:
有時間列就取最大時間列
有自增的id就去最大id
如果是想返回乙個記錄集,並且有時間列的話可以這麼做select 重複列,時間列,其餘列
inner join (select 重複列,max(時間列) as 時間列 from 表 group by 重複列) as t2
on t1.重複列=t2.重複列 and t1.時間列 =t2.時間列
from 表 as t1
17樓:匿名使用者
既然資料都重複,就時間不同,那就取max(時間)就行了吧
select 重複資料的列名1,重複資料的列名2,....,max(時間列) from table group by 重複資料的列名1,重複資料的列名2,....
18樓:匿名使用者
select ... order by time desc
19樓:_神__仙
select * from table t1 ,(select top(dsj) as dsj,czyh from table group by czyh) as t2
where t1.dsj=t2.dsj and t1.czyh =t2.czyh
20樓:匿名使用者
select top 1 * from [表名] where czyh=1151511 order by dsj desc
求sql語句,pl,求乙個sql語句,pl sql
select birthday from select birthday,1 dfrom a where to char sysdate,mmdd to char birthday,mmdd union all select birthday,2 d from a where to char sys...
SQL查詢語句求問
1 利用巢狀查詢 select from 學生表 where studentid in select studentid from 關係表 where teacherid teacherid 此處的 teacherid是變數,替換成老師id就可以了 2 利用內連線查詢,三張表交叉鏈結然後根據條件篩選...
求一條sql語句
我提供的思路如下 select 成績 from a a1 where name 張三 and 成績 in select 成績 from a a2 where name 李四 思路就是外層查詢出所有張三的成績,再在這個集合中通過子查詢出李四的成績來進行篩選,選出來在張三成績集合中存在且又在李四成績集合...
SQL多個關聯表求和語句,sql 多表關聯 求和語句 怎麼寫
設查詢客戶id為 a0001 查詢語句如下 select a.客戶id,a.專案id,sum a.合同數量 as 該專案總的合同數量,sum b.完成數量 as 該專案總的完成數量from tb2 a,tb3 b where a.專案id b.專案id and a.客戶id a0001 group ...
php mysql求一句sql語句
select from select id,substr id,1,2 dd,to number substr id,3 ss from table 0 t order by dd desc ss desc試試這個,再列傳行,應該就可以了 select 欄位名 from 表名 order by 欄位...