如何使用sql語句建立表,表中欄位有id department,其中id唯一,dpartment非空

2021-03-28 14:27:58 字數 2034 閱讀 4515

1樓:大兵我愛你

--建立表,中欄位有id、department,其中id唯一,dpartment非空

create table aaaa(

id varchar(10) not null,department varchar(30) not null,primary key(id))

--查詢,如何在該表中查詢部門人數大於3的部門名稱select department,count(*)from aaaa

where count(*)>3

group by department

插入插入資料就可以了

2樓:孤獨づ瀟灑

create table tablename(id [欄位型別] identity primary key not;

department [欄位型別] not null;

)select * from tablename tn where tn.department>3;

自己再看著改

3樓:匿名使用者

create table [dbo].[部門](

[id] [nchar](10) collate chinese_prc_ci_as not null,

[department] [nchar](10) collate chinese_prc_ci_as not null,

constraint [pk_部門] primary key clustered

([id] asc

)with (ignore_dup_key = off) on [primary]

) on [primary]

查詢一個表中所有id欄位在另一個表中對應值的sql語句怎麼寫?

4樓:匿名使用者

子查詢即可

select (select name from ta where id = tb.id1) as id1,

(select name from ta where id = tb.id2) as id2

from tb

5樓:匿名使用者

--建立bai

測試數du

據zhi

create table #a(id int,name varchar(10))

insert into #a values(1,'a')insert into #a values(2,'b')insert into #a values(3,'c')create table #b(id1 int,id2 int)insert into #b values(1,2)insert into #b values(2,1)insert into #b values(2,3)---------------實現dao

**部內

分容----------------

select

t1.name as name1

,t2.name as name2

from

#b tt

left join #a t1 on tt.id1 =t1.idleft join #a t2 on tt.id2 =t2.id

6樓:匿名使用者

select * from ta,tb where ta.id= tb.id1

7樓:匿名使用者

select c.name,d.name from (select a.

id1 id1,a.id2 id2,a.name name from ta a,tb b where a.

id1=b.id1) temp c

,ta d where c.id2=d.id2

8樓:匿名使用者

select t1.name as name1,t2.name as name2 from ta as t1,ta as t2,tb

where t1.id = tb.id1 and t2.id = tb.id2

資料庫如何建立檢視,怎麼用SQL語句建立檢視?

1.開啟sql server management studio,依次到檢視。2.右鍵點選,選擇新建檢視。3.選中建立 需要的表,然後點選新增。4.新增完後,點選關閉。5.點選表中的核取方塊,來新增一些列,在最下面的框中會自動生成相應。6.也可以在下面的 框中直接輸入一些 7.點選空白處,並使用快捷...

mysql如何使用sql語句判斷記錄是否存在,如果存在就更新記錄中的屬性值把checked從0變為

update table name set checked 1 where macaddr 00 00 00 00 00 01 sql 語句判斷記錄是否存在 方法1 判斷表中是 否存在bai記錄的sql語句du 判斷表中是否存在記錄zhi,我們慣常使用的dao語句是 select count fro...

在C中,如何使用sql語句向資料庫中新增資訊

連線字串 data source localhost 服務bai器名du initial catalog 資料庫名 integrated security true sqlconnection con new sqlconnection 連線字串 string ss sql語句 zhi sql ma...