由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求教一个SQL的问题
相关主题
SQL copy a table into a new table and add a new column (转载)SQL find distinct values in large table (转载)
sql的2个问题SQL check likeness between two large tables (转载)
SQL combine two columns from two different tables no shared columnserror of sql query in MS Access database
sort two same tables SQL but different results (转载)被一个面试题卡的泪流满面 SQL
SQL combine two tables into one table and add a new columnSQL multiply all values of a column in table (转载)
error of executing SQL query of string concatenation (转载SQL fast search in a 10 million records table
SQL add some columns into a table from another tableSQL 面试问题
请教个SQL的问题这题怎么做
相关话题的讨论汇总
话题: select话题: rename话题: table话题: where话题: renaming
进入JobHunting版参与讨论
1 (共1页)
u*****o
发帖数: 1224
1
最近在自学,想请教大家一个renaming的问题
用as可以实现两种renaming, rename一个column, 或者rename一个table
第一种:就是说比如我的table有个column A, 我把A的每个数×10000/2.5(想象一个
特别复杂的数学式,太复杂了以至于我必须rename成B)
然后我想select B-A>1的row
那我必须这么写:select A, A*1000/2.5 as B from...where A*1000/2.5 - A > 1
想用B代替calculated expression (select A, A*1000/2.5*800+6 as B from where B
-A>1) 就不work!!
第二种情况是rename一个table,
select T1.col1, T2.col2
from table1 as T1, table2 as T2 where...
这里rename table的话,我就可以用简写T1,T2出现在表达式里,甚至出现在renaming
的前面。。为什么第一个例子就不能用简写呢
汗,好难说清楚,不知有人听明白了吗。。。
f**********3
发帖数: 295
2
写个你想写的完整表达出来吧
(select A, A*1000/2.5*800+6 as B from where B
-A>1) from后面有table吗?

B

【在 u*****o 的大作中提到】
: 最近在自学,想请教大家一个renaming的问题
: 用as可以实现两种renaming, rename一个column, 或者rename一个table
: 第一种:就是说比如我的table有个column A, 我把A的每个数×10000/2.5(想象一个
: 特别复杂的数学式,太复杂了以至于我必须rename成B)
: 然后我想select B-A>1的row
: 那我必须这么写:select A, A*1000/2.5 as B from...where A*1000/2.5 - A > 1
: 想用B代替calculated expression (select A, A*1000/2.5*800+6 as B from where B
: -A>1) 就不work!!
: 第二种情况是rename一个table,
: select T1.col1, T2.col2

u*****o
发帖数: 1224
3
好,
select A, A*1000/2.5 as B from table
where A*1000/2.5 - A > 1 (不能是where B-A > 1)
from后面有table,就是说我在原table基础上新加了个新算出来的B, 但filter的时候
不能写B,要写出全部算式,是为什么呢?

【在 f**********3 的大作中提到】
: 写个你想写的完整表达出来吧
: (select A, A*1000/2.5*800+6 as B from where B
: -A>1) from后面有table吗?
:
: B

s********u
发帖数: 1109
B*****g
发帖数: 34098
5
去学一下下面这3个的执行次序
SELECT
FROM
WHERE

B

【在 u*****o 的大作中提到】
: 最近在自学,想请教大家一个renaming的问题
: 用as可以实现两种renaming, rename一个column, 或者rename一个table
: 第一种:就是说比如我的table有个column A, 我把A的每个数×10000/2.5(想象一个
: 特别复杂的数学式,太复杂了以至于我必须rename成B)
: 然后我想select B-A>1的row
: 那我必须这么写:select A, A*1000/2.5 as B from...where A*1000/2.5 - A > 1
: 想用B代替calculated expression (select A, A*1000/2.5*800+6 as B from where B
: -A>1) 就不work!!
: 第二种情况是rename一个table,
: select T1.col1, T2.col2

u*****o
发帖数: 1224
6
谢谢,原来是因为
from, where在select之前执行,所以select的alias在where执行的时候不存在。。
又学会一招!很感谢!

【在 B*****g 的大作中提到】
: 去学一下下面这3个的执行次序
: SELECT
: FROM
: WHERE
:
: B

1 (共1页)
进入JobHunting版参与讨论
相关主题
这题怎么做SQL combine two tables into one table and add a new column
compare two large tables SQLerror of executing SQL query of string concatenation (转载
请教一道算法题目,请高手指点SQL add some columns into a table from another table
Error of SQL query on IBM netezza SQL database from Aginity workbench请教个SQL的问题
SQL copy a table into a new table and add a new column (转载)SQL find distinct values in large table (转载)
sql的2个问题SQL check likeness between two large tables (转载)
SQL combine two columns from two different tables no shared columnserror of sql query in MS Access database
sort two same tables SQL but different results (转载)被一个面试题卡的泪流满面 SQL
相关话题的讨论汇总
话题: select话题: rename话题: table话题: where话题: renaming