关于SQL的采访问题......... [英] Interview question on SQL.........

查看:81
本文介绍了关于SQL的采访问题.........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Interivew被问到了一个问题



FIleID FileName IsValid

1 A 0

2 B 0

3 C 1

4 D 0



所以问题是在上表列中isValid可以包含从0到无穷大的任何数值。也就是说,它可以有100,200个同样的b / b
所以如果该列在整个过程中没有相同的值,那么查询应该返回false,否则为true



不使用加入或条件



我尝试了什么:



我正在尝试创建一个函数,但这也不是必需的

I have been asked a quetion in Interivew

FIleID FileName IsValid
1 A 0
2 B 0
3 C 1
4 D 0

So question is that in above table column isValid can contain any numeric value ranging from 0 to infinity.Means it can have 100,200 likewise

so if that column don't have same value throughout then query should return false else true

without using join or where condition

What I have tried:

I am trying to create a function but this also not required

推荐答案

试试这个:

Try this:
IF (SELECT COUNT(*) FROM tablename) = (SELECT COUNT(DISTINCT column_of_interest) FROM tablename)
   SELECT 'FALSE'
ELSE
   SELECT 'TRUE'


不确定我是否理解问题是否正确,但请尝试以下方法:

Not sure if I understand the question correctly, but try the following:
select
   case (select count(*) 
         from (select distinct isValid 
		       from TableName) a)
      when 1 then 'True'
      else 'False'
   end


我们不做你的作业:面试是家庭作业!他们在那里,所以公司可以了解你的技能,并评估你是否适合他们的团队,并且可以完成这项工作 - 如果我愿意的话,那就不行。如果我们为你做这件事,那对任何人都不公平:公司因为面试是一项非常昂贵的业务,其他申请人可以完成任务,可能是工作,最终是你 - 因为一旦公司发现你撒谎在面试中你也不会在工作中持续很长时间。



亲自尝试一下,你可能会发现它并不像你想象的那么难!
We do not do your homework: and interviews are homework! They are there so the company can get an idea of your skills and assess if you fit into their team, and can do the job - not if I do and can. If we do it for you, that isn't fair on anybody: the company because interviewing is a very expensive business, the other applicants who could do the task and presumably the job, and ultimately you - because once the company finds out you lied on the interview you won't last long in the job either.

Try it yourself, you may find it is not as difficult as you think!


这篇关于关于SQL的采访问题.........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆