Need help to understand SQL query (oracle10g) [closed]
I'm new in SQL and need little help to understand parts in this SQL statement
select BUY_VALUE,
SELL_VALUE,
RATE_DAY,
RATE_TIME
from ( SELECT TRIM (b.ticker),
TRIM (TO_CHAR (b.buy_value, '9999999.99')) BUY_VALUE,
TRIM (TO_CHAR (b.sell_value, '9999999.99')) SELL_VALUE,
b.currency,
TO_CHAR (TRUNC (SYSDATE), 'YYYYMMDD') rate_day,
TO_CHAR (SYSDATE, 'HH24MISS') rate_time
FROM portal.gpb_bank_quotes b
WHERE b.ticker = 'GAZP'
)
- what is
b
(b.buy_value) ? FROM portal.gpb_bank_quotes
- is that table name? Is it possible that it delimited with.
- ahhh too difficult ///
Thanks in advance
b
is a table alias forportal.gpb_bank_quotes
. This is handy so that you don't have to typeportal.gpb_bank_quotes.buy_value
, etc.Yes.
portal
is a schema, andgpb_bank_quotes
is a table in that schema.
b
is an alias for the table/view gpb_bank_quotes
which is located in the schema portal
.
EDIT - as per comment from OP:
The SELECT ... FROM ( SELECT... FROM...)
is just using the inner SELECT as a subquery.
The same result for this query could also be obtained without the outer select. The TRUNC on SYSDATE is also redundant if specifying the date format to TO_CHAR
SELECT TRIM (TO_CHAR (b.buy_value, '9999999.99')) BUY_VALUE,
TRIM (TO_CHAR (b.sell_value, '9999999.99')) SELL_VALUE,
TO_CHAR (SYSDATE, 'YYYYMMDD') RATE_DAY,
TO_CHAR (SYSDATE, 'HH24MISS') RATE_TIME
FROM portal.gpb_bank_quotes b
WHERE b.ticker = 'GAZP';
精彩评论