筆試題sql
a)select pname as '商品名',avg(qty) as 平均銷售量 from s,p,m where m.city='上海' and s.mno=m.mno and p.pno=s.pno,select p.Pno,p.pname,sum(s.qty)
from s left join p on s.pno=p.pno left join m on p.Mno=m.Mno
where m.city='上海市'
group by p.Pno,p.pname,p.city,p.color
b)、先刪除Sale表的外鍵PNO,再刪除gds表。
c)聯系:視圖(view)是在基本表之上建立的表,它的結構(即所定義的列)和內容(即所有數據行)都來自基本表,它依據基本表存在而存在。一個視圖可以對應一個基本表,也可以對應多個基本表。視圖是基本表的抽象和在邏輯意義上建立的新關系
區別:1、視圖是已經編譯好的sql語句。而表不是
2、視圖沒有實際的物理記錄。而表有。
3、表是內容,視圖是窗口
4、表只用物理空間而視圖不佔用物理空間,視圖只是邏輯概念的存在,表可以及時四對它進行修改,但視圖只能有創建的語句來修改
5、表是內模式,視圖是外模式
6、視圖是查看數據表的一種方法,可以查詢數據表中某些欄位構成的數據,只是一些SQL語句的集合。從安全的角度說,視圖可以不給用戶接觸數據表,從而不知道表結構。
7、表屬於全局模式中的表,是實表;視圖屬於局部模式的表,是虛表。
8、視圖的建立和刪除隻影響視圖本身,不影響對應的基本表。
❷ 面試題目(sql)
1、忍不住想說一句,因為第一題中的欄位類型是
【日期型】,而各種資料庫操作日期型數據有不同的方法,沒有一種共通的方法,所以脫離了資料庫而言沒有一種共通的sql。
2、select
ID,NAME,ADDRESS,PHONE,LOGDATE
from
T
where
ID
in(
select
ID
from
T
group
by
NAME
having
count(*)>1)
order
by
NAME;
3、delete
from
T
where
ID
not
in
(select
min(id)
from
T
group
by
name);
4、update
T
set
T.ADDRESS=(select
E.ADDRESS
from
E
where
E.NAME=T.NAME),
T.PHONE=(select
E.PHONE
from
E
where
E.NAME=T.NAME);
5、這個不同的資料庫也有不同的處理方法,不能脫離資料庫談了。
如:SqlServer或者access可以使用
top
oracle可以使用
rownum
等
---
以上,希望對你有所幫助。
❸ SQL筆試題
一
一般不用一句話寫
數據部分 select date, sum(num) as num from table group by date
合計部分 select sum(num) as sum from table
如果非要和在一起顯示只能這樣
select date, sum(num) as num from table group by date
union
selec '合計' as date, sum(num) as num from table
二
假設你的月份是數字的話
select t1.person, t1.month, t1.income as 本月收入, t2.income as 上月收入, t2.income as 下月收入 from table t1 inner join table t2 on t1.month=t2.month+1 inner and t1.person=t2.person inner join table t3 on t1.month=t3.month-1 and t1.person=t3.person
假設月份是日期格式(yyyy-mm-dd)
select t1.person, t1.month, t1.income as 本月收入, t2.income as 上月收入, t2.income as 下月收入 from table t1 inner join table t2 on datediff(m,t2.month,t1.month)=1 inner and t1.person=t2.person inner join table t3 on datediff(m,t1.month,t3.month)=1 and t1.person=t3.person
如果能給出月份的實際數據會比較好給你個准確的答案
❹ sql筆試題,幫幫小弟!
二個我都有在我的電腦上測試,都是可以的,請參考。
第一題的答案
SELECT a, COUNT(*)
FROM (SELECT a = CASE WHEN score >= 0 AND
score < 10 THEN '0-9' WHEN score >= 10 AND
score < 20 THEN '10-19' WHEN score >= 20 AND
score < 30 THEN '20-29' WHEN score >= 30 AND
score < 40 THEN '30-39' WHEN score >= 40 AND
score < 50 THEN '40-49' WHEN score >= 50 AND
score < 60 THEN '50-59' WHEN score >= 60 AND
score < 70 THEN '60-69' WHEN score >= 70 AND
score < 80 THEN '70-79' WHEN score >= 80 AND
score < 90 THEN '80-89' WHEN score >= 90 AND
score < 100 THEN '90-99' ELSE '100' END
FROM student) a
GROUP BY a
第二題的答案
SELECT TOP 10 ip, countip
FROM (SELECT ip, COUNT(*) AS countip
FROM records
GROUP BY ip) a
ORDER BY countip DESC
❺ sql筆試題,寫出這個sql
此題的考點是行轉列,可用case when +group by 實現
具體如下
select
s.userid,
max(case when s.typeid=1 then s.vaule END) 手機號碼,
max(case when s.typeid=2 then s.vaule END) 郵箱地址,
max(case when s.typeid=3 then s.vaule END) 固定號碼,
max(case when s.typeid=4 then s.vaule END) 微博名字
from (select a.userid,b.typeid,b.typename,a.vaule from test.messge a,test.baseon b
where a.typeid=b.typeid)s
GROUP BY s.userid
❻ SQL筆試題尋求答案
select count(*) ,case Fwage > 5000 then 1 else 0 end as type1, case fage > 32 then 1 else 0 end as type2 from emploreeinfo group by type1,type2
有個問題啊 就是你的month是什麼形式的 年月日 還是數字形式 我按數字形式給你寫一個啊 如果是年-月的話 回頭再給你寫
我假設是同一年了 如果不是可以在left join 的on後面改條件
select s1.month,sum(s1.consume) as 當月消費, sum(s2.consume) as 上月消費, sum(s3.consume) as 下月消費, from student s1 left join student s2 on s1.month=s2.month+1 left join student s3 on s1.month=s3.month-1 group by s1.month
❼ SQL資料庫筆試題
1 前面加createview 視圖名 as 2 sele 學號 from 學生表 where 學號 in(sele max(成績) from 成績) group by 學號3 類似
❽ sql語句 面試題
這個簡單,看答案,採納吧~
第一題是,用雙top結構就可以查出來
1,select * from 學生表 where 學號 in
(select top 5 學號 from 成績表 where 學號 not in(select top 10 學號 from 成績表 order by 分數) order by 分數)
第二題是比較簡單,用復合函數就行了,having
select 姓名 from 成績表 group by 姓名 having avg(分數)>80
採納吧~
❾ sql筆試題三表聯查求解
select sum (m.order_price) from (select * from sellorders m ,(select * from branch b, storehouse n where b.branch_id = n.branch_id)t where m.store_id = t.store_id and m.delivery_state = 15 and (m.order_price>500) and (date(m.order_time) between '2015-03-01' and '2015-03-31') and b.branch_id = ?)
傳個分公司ID參數就能查到這個公司的了。
❿ sql筆試題
兩個表第一個store(store_id,city,space)
第二個employee(store_id,emp_id,salary)
1、每家店的平均工資
select t1.store_id,AVG(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.store_id
2、每個城市的平均工資
select t1.city,AVG(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.city
3、查找該城市存在員工工資低於1000的城市信息
select distinct t1.city
from store t1 inner join employee t2 on t1.store_id=t2.store_id
where t2.salary<1000
4、查找城市其職工工資有低於1000的該城市職工平均工資
select t1.city,avg(t2.salary)
from store t1 inner join employee t2 on t1.store_id=t2.store_id
where exists(select * from employee t3
where t1.store_id=t3.store_id and t3.salary<1000)
group by t1.city
其他的自己看吧,比較簡單
5、每個城市工資最高的員工信息
select t2.city,t1.* from employee t1 inner join store t2 on t1.store_id=t2.store_id
where exists(
select * from (
select t1.city,max(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.city) tt where t1.city=tt.city and t2.salary=tt.salary)
6、查詢每個城市的員工總工資,總的店面面積(?),門店的數量,員工數量,最高/最低工資數