久久久久久久性爱潮,国产又粗又猛又爽又黄下载视频,尤物国产在线一区视频,欧美日本国产在线不卡

<sup id="4uqqy"><ol id="4uqqy"></ol></sup>
  • <th id="4uqqy"></th>

      • <strike id="4uqqy"><nobr id="4uqqy"><ins id="4uqqy"></ins></nobr></strike><sup id="4uqqy"></sup><strong id="4uqqy"><u id="4uqqy"></u></strong>
        <sub id="4uqqy"></sub>

          綠色資源網(wǎng):您身邊最放心的安全下載站! 最新軟件|熱門(mén)排行|軟件分類(lèi)|軟件專題|廠商大全

          綠色資源網(wǎng)

          技術(shù)教程
          您的位置:首頁(yè)數(shù)據(jù)庫(kù)類(lèi)SQL Server → sql 多表查詢 Select語(yǔ)句查詢實(shí)例分析

          sql 多表查詢 Select語(yǔ)句查詢實(shí)例分析

          我要評(píng)論 2012/01/29 12:19:05 來(lái)源:綠色資源網(wǎng) 編輯:downcc.com [ ] 評(píng)論:0 點(diǎn)擊:469次

          --1、查找員工的編號(hào)、姓名、部門(mén)和出生日期,如果出生日期為空值,
          --顯示日期不詳,并按部門(mén)排序輸出,日期格式為yyyy-mm-dd。
          select emp_no ,emp_name ,dept ,
          isnull(convert(char(10),birthday,120),'日期不詳') birthday
          from employee
          order by dept

          --2、查找與喻自強(qiáng)在同一個(gè)單位的員工姓名、性別、部門(mén)和職稱
          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)的總工資
          select dept,sum(salary)
          from employee
          group by dept

          --4、查找商品名稱為14寸顯示器商品的銷(xiāo)售情況,
          --顯示該商品的編號(hào)、銷(xiāo)售數(shù)量、單價(jià)和金額
          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、在銷(xiāo)售明細(xì)表中按產(chǎn)品編號(hào)進(jìn)行匯總,統(tǒng)計(jì)每種產(chǎn)品的銷(xiāo)售數(shù)量和金額
          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年的訂單總金額
          select cust_id,sum(tot_amt) totprice
          from sales
          where convert(char(4),order_date,120)='1996'
          group by cust_id

          --7、查找有銷(xiāo)售記錄的客戶編號(hào)、名稱和訂單總額
          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年中有銷(xiāo)售記錄的客戶編號(hào)、名稱和訂單總額
          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、查找一次銷(xiāo)售最大的銷(xiāo)售記錄
          select order_no,cust_id,sale_id,tot_amt
          from sales
          where tot_amt=
          (select max(tot_amt)
          from sales)

          --10、查找至少有3次銷(xiāo)售的業(yè)務(wù)員名單和銷(xiāo)售日期
          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)有訂貨記錄的客戶名稱
          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)排序,同一客戶再按訂單降序排序輸出
          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的銷(xiāo)售情況,要求顯示相應(yīng)的銷(xiāo)售員的姓名、
          --性別,銷(xiāo)售日期、銷(xiāo)售數(shù)量和金額,其中性別用男、女表示
          select emp_name 姓名, 性別= case a.sex when 'm' then '男'
          when 'f' then '女'
          else '未'
          end,
          銷(xiāo)售日期= 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è)人的銷(xiāo)售記錄,要求顯示銷(xiāo)售員的編號(hào)、姓名、性別、
          --產(chǎn)品名稱、數(shù)量、單價(jià)、金額和銷(xiāo)售日期
          select emp_no 編號(hào),emp_name 姓名, 性別= case a.sex when 'm' then '男'
          when 'f' then '女'
          else '未'
          end,
          prod_name 產(chǎn)品名稱,銷(xiāo)售日期= 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、查找銷(xiāo)售金額最大的客戶名稱和總貨款
          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、查找銷(xiāo)售總額少于1000元的銷(xiāo)售員編號(hào)、姓名和銷(xiāo)售額
          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、查找至少銷(xiāo)售了3種商品的客戶編號(hào)、客戶名稱、商品編號(hào)、商品名稱、數(shù)量和金額
          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ā)公司銷(xiāo)售相同的客戶編號(hào)、名稱和商品編號(hào)、商品名稱、數(shù)量和金額
          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),薪水
          select emp_no,emp_name,dept,salary
          from employee
          where emp_name like '劉%'

          20、查找所有定單金額高于2000的所有客戶編號(hào)
          select cust_id
          from sales
          where tot_amt>2000

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

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

          23、將表中住址為"上海市"的員工住址改為"北京市"
          update employee
          set addr like '北京市'
          where addr like '上海市'

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

          25、顯示每種產(chǎn)品的銷(xiāo)售金額總和,并依銷(xiāo)售金額由大到小輸出。
          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)、客戶名稱、客戶地址。
          select CUST_ID,cust_name,addr
          from customer
          where cust_id between 'C0001' AND 'C0004'

          27、計(jì)算出一共銷(xiāo)售了幾種產(chǎn)品。
          select count(distinct prod_id) as '共銷(xiāo)售產(chǎn)品數(shù)'
          from sale_item

          28、將業(yè)務(wù)部員工的薪水上調(diào)3%。
          update employee
          set salary=salary*1.03
          where dept='業(yè)務(wù)'

          29、由employee表中查找出薪水最低的員工信息。
          select *
          from employee
          where salary=
          (select min(salary )
          from employee )

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

          關(guān)鍵詞:sql,多表查詢,Select語(yǔ)句

          閱讀本文后您有什么感想? 已有 人給出評(píng)價(jià)!

          • 0 歡迎喜歡
          • 0 白癡
          • 0 拜托
          • 0 哇
          • 0 加油
          • 0 鄙視