問這個SQL語句該怎樣寫,sql語句應該怎樣寫?

2022-06-27 23:12:09 字數 4404 閱讀 2092

1樓:

delete from table where a not in --刪除主鍵不在其中的多餘資料

(select min(a) from table group by b,c)--按照b,c分組查詢出最小的主鍵

2樓:

不確定你的資料庫,以及版本是什麼.

你可以用 olap 函式 row_number()撇開主鍵 a

這是個 db2 的列子, 可以用來去除重複列select b, c from (select row_number() over (partition by b, c) as row_num, b, c from tab1) a where a.row_num >1

不好意思, 我這個是選出重複列了 ...

3樓:匿名使用者

假設表名temp,a是主鍵,所以不會重複

故下句即可滿足使用

delete from temp t

where not exists(select t.a=r.maxa(select max(a) as maxa from temp sgroup by s.b,s.c

) r);

4樓:

既然a是主鍵,那怎麼可能可以合併呢?刪除b,c重覆記錄的話那你主鍵最後是怎麼安排的?

提供查詢唯一b,c記錄的方法:

select b,c from your_tableunion

select b,c from your_table;

5樓:匿名使用者

2005的解決方案:

with cte (col1,col2, duplicatecount)

as( select a,b,

row_number() over(partition by a,b order by a) as duplicatecount

from duplicatercordtable

) delete

from cte

where duplicatecount > 1

go2000的解決方案:

需要新建乙個輔助欄位id

delete

from duplicatercordtable

where id not in

( select max(id)

from mytable

group by a, b)

參考:http://www.

6樓:石亮東

delete from tablename ta where a<(select max(a) from tablename tb where ta.b=tb.b and ta.

c=tb.c)

這樣就可以刪除了.

然後select * from tablename

7樓:匿名使用者

也就說要刪除重複的資料

delete from biao t where exists (select max(t1.id) from biao t1 where t.id= t1.

id group by b,c);

commit;

你執行下這個試試

8樓:

這裡有解決辦法,雖然是針對oracle的,但對sqlserver同樣適用,你可以參考一下。

9樓:匿名使用者

select distinct t.* from table t order by t.a

10樓:匿名使用者

select b,c from table group by b,c

11樓:匿名使用者

select distinct b,c from 表

12樓:匿名使用者

select distinct(select b ,c from table where b=c) from table

13樓:匿名使用者

declare @a char @b charset @b=set @a=(select distinct b from a)

where @a=select c from aprint @a

print @b

14樓:

我看了半天,硬是不懂你在說什麼

15樓:匿名使用者

shenme什麼意思?

sql語句應該怎樣寫?

16樓:蝸牛p科技

sql語句將乙個表的某個值加1或減1,直接用update語句即可。

工具:mysql 5.6

步驟:1、如圖,student表中有如下資料:

3、執行後結果:

請問sql語句該如何寫?

17樓:口q口

sql dml 和 ddl

可以把 sql 分為兩個部分:資料操作語言 (dml) 和 資料定義語言 (ddl)。

sql (結構化查詢語言)是用於執行查詢的語法。但是 sql 語言也包含用於更新、插入和刪除記錄的語法。

查詢和更新指令構成了 sql 的 dml 部分:

select - 從資料庫表中獲取資料

update - 更新資料庫表中的資料

delete - 從資料庫表中刪除資料

insert into - 向資料庫表中插入資料sql 的資料定義語言 (ddl) 部分使我們有能力建立或刪除**。我們也可以定義索引(鍵),規定表之間的鏈結,以及施加表間的約束。

sql 中最重要的 ddl 語句:

create database - 建立新資料庫alter database - 修改資料庫create table - 建立新錶

alter table - 變更(改變)資料庫表drop table - 刪除表

create index - 建立索引(搜尋鍵)drop index - 刪除索引

這個sql語句該如何寫,請寫出完整的sql語句

18樓:司馬刀劍

使用sql 萬用字元可以替代乙個或多個字元,即模糊查詢,也就是包含關係。

sql 萬用字元必須與 like 運算子一起使用。在 sql 中,可使用以下萬用字元如下:

1、%    替代乙個或多個字元

2、_    僅替代乙個字元

3、[charlist]    字元列中的任何單一字元

4、[^charlist]或者[!charlist] 不在字元列中的任何單一字元

以圖中**為例,說明一下各萬用字元用法

1、 查詢居住在以 "ne" 開始的城市裡的人:

select * from persons where city like 'ne%'

2、查詢居住在包含 "lond" 的城市裡的人:

select * from persons where city like '%lond%'

3、查詢名字的第乙個字元之後是 "eorge" 的人:

select * from persons where firstname like '_eorge'

4、查詢記錄的姓氏以 "c" 開頭,然後是乙個任意字元,然後是 "r",然後是任意字元,然後是 "er":

select * from persons where lastname like 'c_r_er'

5、查詢居住的城市以 "a" 或 "l" 或 "n" 開頭的人:

select * from persons where city like '[aln]%'

6、查詢居住的城市不以 "a" 或 "l" 或 "n" 開頭的人:

select * from persons where city like '[!aln]%'

這個sql語句應該怎麼寫?

19樓:腦子有病是吧

select id from tbl-a,tbl-b where tbl-a.name=tbl-b.name

SQL高手幫我看下這個SQL語句應該怎麼寫才正確

其實你可以在 sql select len replace fentan name,from zhang 之後把 sql writ 出來,看看和 select len fentan name from zhang 有什麼區別就知道問題再 了。要學會除錯和查詢bug。如果你要的是字段裡的值去掉逗號後的...

Sql這條語句該怎麼寫!求大神幫助

囂張的農村人 delete building where 開盤 in select max 開盤 building where 樓盤名稱 龍湖觀山水 sql查詢語句,求大神幫助!這樣的sql語句怎麼寫?求大神幫忙 使用 max 函式就可以了 select select max a from tabl...

怎樣sql儲存過程中執行動態sql語句

有時需要在oracle 儲存過程中執行動態sql 語句 例如表名是動態的,或字段是動態的,或查詢命令是動態的,可用下面的方法 set serveroutput ondeclaren number sql stmt varchar2 50 t varchar2 20 beginexecute imme...