数据库面试题

来源:互联网 发布:淘宝店铺突然没流量 编辑:程序博客网 时间:2024/06/06 00:13

    1.面试题  一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数。 

 ------------------------------------------  

select id, Count(*) from tb group by id having count(*)>1 select * from(select count(ID) as count from table group by     ID)T where T.count>1 

    

    2.请教一个面试中遇到的SQL语句的查询问题  表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。

 ------------------------------------------ 

select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name 

    

    3.面试题:一个日期判断的sql语句?  请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)

  ------------------------------------------  

select * from tb where datediff(dd,SendTime,getdate())=0 

原创粉丝点击