sql - oracle: can you assign an alias to the from clause? -


can assign alias clause? like:

select - b "markup" retail a, cost b; 

edit: sorry typed out bit quick , tried simplify question point didnt make sense

what im trying use aliases compare months between 2 publishing dates in same table. here's found works:

select distinct to_char(months_between((select distinct pubdate                                         books3                                          pubid = 2),                                         (select distinct pubdate                                          books3                                          pubid = 4)), '99.99') "answer"                               books3 

i wanted looks this:

select distinct months_between(a,b) (select distinct pubdate         books3         pubid = 2 a),       (select distinct pubdate        books3        pubid = 4 b) 

but isn't working

yes, oracle supports table aliases. supports as in select list not in from list:

select a.col - b.col markup   retail a,        cost b  b.id = a.id 

most databases support omitting as keyword.

that said, table aliases aren't column aliases -- still need reference specific column in respective table in select clause, see in update of example. added where criteria query wouldn't returning cartesian product.

table aliases required derived tables/inline views (aka subquery, though find terminology vague):

select x.col   (select t.col,                max(t.date)           table t       group t.col) x 

here's query:

your problem putting table alias inside derived table, when needs outside brackets/parenthesis:

select distinct to_char(months_between(x.pubdate, y.pubdate), '99.99') "answer"  (select distinct a.pubdate books3 a.pubid = 2) x,       (select distinct b.pubdate books3 b b.pubid = 4) y 

the reason need distinct because of cartesian product.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -