问题描述
Table1
----------
name age address city state
------------------------------------------------------------
ram 10 asdf asdfrg tn
kumar 20 fyudfy adfgdfgfd ap
raj 15 asfgafg asfgfg up
sai 25 asdfgaf asfgasfg ka
dachu 23 afgfagg fdgfgfgg jk
我想要输出=
I want the output is =
age
----
15
无需找到条件
例如:
栏(年龄,raj)
此类型在SQL或ACCESS或MYSQL中有任何函数。
请帮助...
without where condition to find
eg:
column(age,raj)
this type of any function is there in SQL or ACCESS or MYSQL.
Pls help...
推荐答案
的引用会有所帮助,这种类型的任何函数都在那里在SQL或ACCESS或MYSQL
this type of any function is there in SQL or ACCESS or MYSQL
中让我想到 []
Of显示的数据
leads me to think of mathematical functions[^]
Of the data shown
Average = 18
Median = 20
There is no mode
然而范围 是 15因此此查询将获得您想要的结果:
However the range is 15 so this query will get the results you want:
select max(age) - min(age) as ageRange from Table1
我上面的一些讽刺解决方案并没有那么顺利。但是,尽管其他成员说,但可以过滤表而不使用 WHERE
。真正的一点是,你真的不应该这样做! (我真的很有意思)。
可以使用 []和 []声明。例如:
My somewhat sarcastic solution above didn't go down so well. However, despite what other members are saying it is possible to filter the table without using WHERE
. The real point is that you really shouldn't do it this way! (And I really do mean really).
It can be achieved using a CURSOR[^] and an IF[^] statement. For example:
declare @AgeToCheck int = 15
declare @ResultFound int = 0
declare @name varchar(125)
declare @age int
declare @address varchar(125)
declare @city varchar(125)
declare @state varchar(125)
DECLARE @ACursor CURSOR
SET @ACursor = CURSOR FOR
SELECT [name], age,[address], city,[state]
FROM Table1
OPEN @ACursor
FETCH NEXT FROM @ACursor INTO @name, @age, @address, @city, @state
WHILE @@FETCH_STATUS = 0
BEGIN
IF @age = @AgeToCheck
BEGIN
SET @ResultFound = 1
BREAK
END
FETCH NEXT FROM @ACursor INTO @name, @age, @address, @city, @state
END
CLOSE @ACursor
DEALLOCATE @ACursor
select @name,@age,@address,@city,@state
现在没有与
Now doesn't that look horrible compared to
SELECT [name], age,[address], city,[state]
FROM Table1
WHERE age = @AgeToCheck
我不能强调这一点,因为有些事情是可能的并不意味着它是一个明智的解决方案。不要使用游标过滤表。
I cannot stress strongly enough that, just because something is possible does not mean that it is a sensible solution. Do not filter tables using Cursors.
这篇关于如何在sql中查找特定的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!