日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

DB2比較常用與實(shí)用sql語(yǔ)句總結(jié)

瀏覽:261日期:2023-03-24 09:22:32
1、查找員工的編號(hào)、姓名、部門(mén)和出生日期,如果出生日期為空值,顯示日期不詳,并按部門(mén)排序輸出,日期格式為yyyy-mm-dd。
復(fù)制代碼 代碼如下:
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),"日期不詳") birthday
from employee
order by dept



  2、查找與喻自強(qiáng)在同一個(gè)單位的員工姓名、性別、部門(mén)和職稱
復(fù)制代碼 代碼如下:
select emp_no,emp_name,dept,title
from employee
where emp_name<>"喻自強(qiáng)" and dept in
(select dept from employee
where emp_name="喻自強(qiáng)")


  3、按部門(mén)進(jìn)行匯總,統(tǒng)計(jì)每個(gè)部門(mén)的總工資
復(fù)制代碼 代碼如下:
select dept,sum(salary)
from employee
group by dept


  4、查找商品名稱為14寸顯示器商品的銷售情況,顯示該商品的編號(hào)、銷售數(shù)量、單價(jià)和金額
復(fù)制代碼 代碼如下:
select a.prod_id,qty,unit_price,unit_price*qty totprice
from sale_item a,product b
where a.prod_id=b.prod_id and prod_name="14寸顯示器"


  5、在銷售明細(xì)表中按產(chǎn)品編號(hào)進(jìn)行匯總,統(tǒng)計(jì)每種產(chǎn)品的銷售數(shù)量和金額
復(fù)制代碼 代碼如下:
select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
from sale_item
group by prod_id



  6、使用convert函數(shù)按客戶編號(hào)統(tǒng)計(jì)每個(gè)客戶1996年的訂單總金額
復(fù)制代碼 代碼如下:
select cust_id,sum(tot_amt) totprice
from sales
where convert(char(4),order_date,120)="1996"
group by cust_id


  7、查找有銷售記錄的客戶編號(hào)、名稱和訂單總額
復(fù)制代碼 代碼如下:
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id
group by a.cust_id,cust_name

  8、查找在1997年中有銷售記錄的客戶編號(hào)、名稱和訂單總額
復(fù)制代碼 代碼如下:
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id and convert(char(4),order_date,120)="1997"
group by a.cust_id,cust_name

  9、查找一次銷售最大的銷售記錄
復(fù)制代碼 代碼如下:
select order_no,cust_id,sale_id,tot_amt
from sales
where tot_amt=
(select max(tot_amt)
from sales)

  10、查找至少有3次銷售的業(yè)務(wù)員名單和銷售日期
復(fù)制代碼 代碼如下:
select emp_name,order_date
from employee a,sales b
where emp_no=sale_id and a.emp_no in
(select sale_id
from sales
group by sale_id
having count(*)>=3)
order by emp_name


  11、用存在量詞查找沒(méi)有訂貨記錄的客戶名稱
復(fù)制代碼 代碼如下:
select cust_name
from customer a
where not exists
(select *
from sales b
where a.cust_id=b.cust_id)


  12、使用左外連接查找每個(gè)客戶的客戶編號(hào)、名稱、訂貨日期、訂單金額訂貨日期不要顯示時(shí)間,日期格式為yyyy-mm-dd按客戶編號(hào)排序,同一客戶再按訂單降序排序輸出
復(fù)制代碼 代碼如下:
select a.cust_id,cust_name,convert(char(10),order_date,120),tot_amt
from customer a left outer join sales b on a.cust_id=b.cust_id
order by a.cust_id,tot_amt desc


  13、查找16M DRAM的銷售情況,要求顯示相應(yīng)的銷售員的姓名、性別,銷售日期、銷售數(shù)量和金額,其中性別用男、女表示
復(fù)制代碼 代碼如下:
select emp_name 姓名, 性別= case a.sex when "m" then "男"
when "f" then "女"
else "未"
end,
銷售日期= isnull(convert(char(10),c.order_date,120),"日期不詳"),
qty 數(shù)量, qty*unit_price as 金額
from employee a, sales b, sale_item c,product d
where d.prod_name="16M DRAM" and d.prod_id=c.prod_id and
a.emp_no=b.sale_id and b.order_no=c.order_no


  14、查找每個(gè)人的銷售記錄,要求顯示銷售員的編號(hào)、姓名、性別、產(chǎn)品名稱、數(shù)量、單價(jià)、金額和銷售日期
復(fù)制代碼 代碼如下:
select emp_no 編號(hào),emp_name 姓名, 性別= case a.sex when "m" then "男"
when "f" then "女"
else "未"
end,
prod_name 產(chǎn)品名稱,銷售日期= isnull(convert(char(10),c.order_date,120),"日期不詳"),
qty 數(shù)量, qty*unit_price as 金額
from employee a left outer join sales b on a.emp_no=b.sale_id , sale_item c,product d
where d.prod_id=c.prod_id and b.order_no=c.order_no



  15、查找銷售金額最大的客戶名稱和總貨款
復(fù)制代碼 代碼如下:
select cust_name,d.cust_sum
from customer a,
(select cust_id,cust_sum
from (select cust_id, sum(tot_amt) as cust_sum
from sales
group by cust_id ) b
where b.cust_sum =
( select max(cust_sum)
from (select cust_id, sum(tot_amt) as cust_sum
from sales
group by cust_id ) c )
) d
where a.cust_id=d.cust_id


16、查找銷售總額少于1000元的銷售員編號(hào)、姓名和銷售額
復(fù)制代碼 代碼如下:
select emp_no,emp_name,d.sale_sum
from employee a,
(select sale_id,sale_sum
from (select sale_id, sum(tot_amt) as sale_sum
from sales
group by sale_id ) b
where b.sale_sum <1000
) d
where a.emp_no=d.sale_id


  17、查找至少銷售了3種商品的客戶編號(hào)、客戶名稱、商品編號(hào)、商品名稱、數(shù)量和金額
復(fù)制代碼 代碼如下:
select a.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price
from customer a, product b, sales c, sale_item d
where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
c.order_no=d.order_no and a.cust_id in (
select cust_id
from (select cust_id,count(distinct prod_id) prodid
from (select cust_id,prod_id
from sales e,sale_item f
where e.order_no=f.order_no) g
group by cust_id
having count(distinct prod_id)>=3) h )


  18、查找至少與世界技術(shù)開(kāi)發(fā)公司銷售相同的客戶編號(hào)、名稱和商品編號(hào)、商品名稱、數(shù)量和金額
復(fù)制代碼 代碼如下:
select a.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price
from customer a, product b, sales c, sale_item d
where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
c.order_no=d.order_no and not exists
(select f.*
from customer x ,sales e, sale_item f
where cust_name="世界技術(shù)開(kāi)發(fā)公司" and x.cust_id=e.cust_id and
e.order_no=f.order_no and not exists
( select g.*
from sale_item g, sales h
where g.prod_id = f.prod_id and g.order_no=h.order_no and
h.cust_id=a.cust_id)
)

  19、查找表中所有姓劉的職工的工號(hào),部門(mén),薪水
復(fù)制代碼 代碼如下:
select emp_no,emp_name,dept,salary
from employee
where emp_name like "劉%"


  20、查找所有定單金額高于2000的所有客戶編號(hào)
復(fù)制代碼 代碼如下:
select cust_id
from sales
where tot_amt>2000


  21、統(tǒng)計(jì)表中員工的薪水在4000-6000之間的人數(shù)
復(fù)制代碼 代碼如下:
select count(*)as 人數(shù)
from employee
where salary between 4000 and 6000


  22、查詢表中的同一部門(mén)的職工的平均工資,但只查詢"住址"是"上海市"的員工
復(fù)制代碼 代碼如下:
select avg(salary) avg_sal,dept
from employee
where addr like "上海市%"
group by dept


  23、將表中住址為"上海市"的員工住址改為"北京市"
復(fù)制代碼 代碼如下:
update employee
set addr like "北京市"
where addr like "上海市"


  24、查找業(yè)務(wù)部或會(huì)計(jì)部的女員工的基本信息。
復(fù)制代碼 代碼如下:
select emp_no,emp_name,dept
from employee
where sex="F"and dept in ("業(yè)務(wù)","會(huì)計(jì)")


  25、顯示每種產(chǎn)品的銷售金額總和,并依銷售金額由大到小輸出。
復(fù)制代碼 代碼如下:
select prod_id ,sum(qty*unit_price)
from sale_item
group by prod_id
order by sum(qty*unit_price) desc


26、選取編號(hào)界于"C0001"和"C0004"的客戶編號(hào)、客戶名稱、客戶地址。
復(fù)制代碼 代碼如下:
select CUST_ID,cust_name,addr
from customer
where cust_id between "C0001" AND "C0004"

  27、計(jì)算出一共銷售了幾種產(chǎn)品。
復(fù)制代碼 代碼如下:
select count(distinct prod_id) as "共銷售產(chǎn)品數(shù)"
from sale_item

  28、將業(yè)務(wù)部員工的薪水上調(diào)3%。
復(fù)制代碼 代碼如下:
update employee
set salary=salary*1.03
where dept="業(yè)務(wù)"

  29、由employee表中查找出薪水最低的員工信息。
復(fù)制代碼 代碼如下:
select *
from employee
where salary=
(select min(salary )
from employee )

  30、使用join查詢客戶姓名為"客戶丙"所購(gòu)貨物的"客戶名稱","定單金額","定貨日期","電話號(hào)碼"
復(fù)制代碼 代碼如下:
select a.cust_id,b.tot_amt,b.order_date,a.tel_no
from customer a join sales b
on a.cust_id=b.cust_id and cust_name like "客戶丙"


  31、由sales表中查找出訂單金額大于"E0013業(yè)務(wù)員在1996/10/15這天所接每一張訂單的金額"的所有訂單。
復(fù)制代碼 代碼如下:
select *
from sales
where tot_amt>all
(select tot_amt
from sales
where sale_id="E0013"and order_date="1996/10/15")
order by tot_amt


  32、計(jì)算"P0001"產(chǎn)品的平均銷售單價(jià)
復(fù)制代碼 代碼如下:
select avg(unit_price)
from sale_item
where prod_id="P0001"


  33、找出公司女員工所接的定單
復(fù)制代碼 代碼如下:
select sale_id,tot_amt
from sales
where sale_id in
(select sale_id from employee
where sex="F")



  34、找出同一天進(jìn)入公司服務(wù)的員工
復(fù)制代碼 代碼如下:
select a.emp_no,a.emp_name,a.date_hired
from employee a
join employee b
on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
order by a.date_hired


  35、找出目前業(yè)績(jī)超過(guò)232000元的員工編號(hào)和姓名。
復(fù)制代碼 代碼如下:
select emp_no,emp_name
from employee
where emp_no in
(select sale_id
from sales
group by sale_id
having sum(tot_amt)<232000)
標(biāo)簽: DB2
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
久久精品网址| 激情久久99| 亚洲字幕久久| 日韩不卡一区二区三区| 美国三级日本三级久久99| 亚洲毛片一区| 麻豆久久久久久| 久久国产日本精品| 午夜在线视频观看日韩17c| 亚洲综合婷婷| 美女av一区| 天堂中文在线播放| 午夜在线一区二区| 日韩不卡手机在线v区| 国产一区二区精品福利地址| 伊人精品一区| 亚洲精品大全| 韩国一区二区三区视频| 香蕉人人精品| 欧美日韩水蜜桃| 日韩一二三区在线观看| 国产一区2区| 性欧美69xoxoxoxo| 国产毛片精品| 激情婷婷欧美| 91精品丝袜国产高跟在线| 国产成人精品一区二区免费看京| 日韩午夜精品| 免费在线欧美黄色| 亚洲欧美久久久| 免费精品一区| 国产午夜精品一区二区三区欧美 | 亚洲成人av观看| 一二三区精品| 精品国产欧美日韩| 中文无码日韩欧| 日本在线高清| 日韩av成人高清| 久久蜜桃精品| 国产精品一级| 99国产成+人+综合+亚洲欧美| 久久wwww| 蜜臀精品久久久久久蜜臀| 中文字幕在线官网| 中文字幕日韩亚洲| 日本蜜桃在线观看视频| 欧美日韩伊人| 欧美日韩精品一本二本三本| 国产精品亚洲综合久久| 日韩视频中文| 91麻豆国产自产在线观看亚洲| 日韩一区二区三区精品| 亚州av乱码久久精品蜜桃| 国产一区二区三区探花| 日韩高清成人在线| 在线国产一区二区| 国产传媒av在线| 欧美亚洲三级| 首页欧美精品中文字幕| 亚洲v在线看| 国产精品xxx在线观看| 老司机精品久久| 桃色一区二区| 久久一区亚洲| 日韩av一区二区三区| 国产亚洲在线| 国产精选在线| 久久中文字幕一区二区三区| 日韩精彩视频在线观看| 视频在线观看一区| 五月精品视频| 99成人在线视频| 国产一区二区三区四区| 国产午夜久久av| 在线看片日韩| 999国产精品视频| 亚洲精品永久免费视频| 欧美激情视频一区二区三区免费 | 深夜视频一区二区| 欧美aaaaaa午夜精品| 69堂免费精品视频在线播放| 视频一区二区三区中文字幕| 黑丝美女一区二区| 999久久久精品国产| 亚洲黄色免费看| 欧美成人精品一级| 国产精品一区高清| 国产免费播放一区二区| 日韩高清不卡一区二区| 亚洲精选av| 综合国产精品| 国产毛片久久| 亚洲一区激情| 国产综合欧美| 亚洲激情中文在线| 不卡在线一区二区| 一区二区小说| 精品一区三区| 亚洲综合日韩| 99视频一区| 久久麻豆精品| 99久久久久久中文字幕一区| 亚洲精品国产嫩草在线观看 | 亚洲激情社区| 国产免费成人| 国产精品呻吟| 亚洲精品乱码日韩| 亚洲精品进入| 亚洲精品日韩久久| 久久精品72免费观看| 7777精品| 蘑菇福利视频一区播放| 亚洲欧洲另类| 亚洲黄色在线| 亚洲区欧美区| 国产精品一二| 欧美国产偷国产精品三区| 欧美日韩视频免费观看| 免费av一区二区三区四区| 久久亚洲电影| 日本少妇精品亚洲第一区| 国产精品久久久久久妇女| 久久69成人| 久久激情网站| 久久亚洲精品伦理| 国产亚洲欧美日韩在线观看一区二区| 日韩av中文在线观看| 国产精品观看| av高清不卡| 中文久久精品| 日韩精品一区二区三区中文在线| 国产日韩欧美| 在线精品亚洲欧美日韩国产| 久久天堂成人| 国产美女一区| 国产精品最新| 水蜜桃久久夜色精品一区| 精品国模一区二区三区| 精品91久久久久| 日韩黄色av| 国产一区丝袜| 日韩欧美精品综合| 日韩视频中文| 国产日韩高清一区二区三区在线 | 韩国久久久久久| 欧美好骚综合网| 99久久久久久中文字幕一区| 午夜在线播放视频欧美| 日韩av影院| 日韩精品一级中文字幕精品视频免费观看 | 一区二区精彩视频| 久久精品国产大片免费观看| 亚洲免费影院| 97精品久久| 国产精品巨作av| 国产精品白丝一区二区三区| 美女久久网站| 综合亚洲色图| 精品女同一区二区三区在线观看| 国产精品嫩草影院在线看| av资源亚洲| 亚洲ab电影| 日韩国产一区二区| 亚洲理论在线| 国产欧美日韩影院| 激情综合婷婷| 亚洲精品一区二区在线看| 亚洲精品系列| 久久字幕精品一区| 国产一区观看| 日本亚洲视频| 亚洲精品**中文毛片| 香蕉久久夜色精品国产| 日韩av不卡在线观看| 欧美激情在线精品一区二区三区| 韩日一区二区| 石原莉奈在线亚洲二区| 久久a爱视频| 久草免费在线视频| 欧美精品自拍| 另类综合日韩欧美亚洲| 99pao成人国产永久免费视频 | av不卡免费看| 91精品日本| 久久久久久夜| 免费久久99精品国产自在现线| 国产精品一区二区精品| 久久国产电影| 亚洲日产国产精品| 亚洲精品国产嫩草在线观看| 日韩精品久久久久久久软件91| 蜜桃精品在线| 亚洲免费毛片| 日韩深夜视频| 日本视频在线一区| 国产精品av一区二区| 久久精品一本| 亚洲一区二区三区无吗| 国产中文在线播放| 快she精品国产999|