zoukankan      html  css  js  c++  java
  • Sql常见面试题(总结)

    1.用一条SQL语句 查询出每门课都大于80分的学生姓名 

    name   kecheng   fenshu
    张三     语文       81
    张三     数学       75
    李四     语文       76
    李四     数学       90
    王五     语文       81
    王五     数学       100
    王五     英语       90

    A: select distinct name from table  where  name not in (select distinct name from table where fenshu<=80)

    2.学生表 如下:
    自动编号   学号   姓名 课程编号 课程名称 分数
    1        2005001  张三  0001      数学    69
    2        2005002  李四  0001      数学    89
    3        2005001  张三  0001      数学    69
    删除除了自动编号不同,其他都相同的学生冗余信息

    A: delete tablename where 自动编号 not in(select min(自动编号) from tablename group by 学号,姓名,课程编号,课程名称,分数)

    3. 表A(单位名称,单位帐号), 表B(单位编号,个人账号)

    列出各单位的名称,账号,以及单位的人数

    select A.name, A.dwzh, isnull(Ct.Quantity,'0') as Quantity from A
    left join

    (select dwzh, count(*) as Quantity from B
    group by dwzh) as Ct

    on A.dwzh = Ct.dwzh


    4. 股票表(股票代码,买卖类型,数量)

    按照股票代码列出,买的数量,卖的数量。

    select isnull(a.StockID, b.StockID), isnull(a.S,'0'), isnull(b.B,'0') from (
    select StockID,sum(quantity) as S from stocks
    where sType = 's'
    group by StockID ) a

    full join (

    select StockID,sum(quantity) as B from stocks
    where sType = 'b'
    group by StockID ) b

    on a.StockID = b.StockID


    5. select * from tempT where ','+ tempT.description + ',' like '%,1,%'

  • 相关阅读:
    ble_app_hrs心率程序 nrf51822
    2019.05.08 《Linux驱动开发入门与实战》
    函数指针
    typedef
    回调函数
    android2
    android1
    每周总结2
    HTML
    数组(续)
  • 原文地址:https://www.cnblogs.com/silva/p/195715.html
Copyright © 2011-2022 走看看