开发者

Need help to understand SQL query (oracle10g) [closed]

开发者 https://www.devze.com 2023-04-06 07:33 出处:网络
开发者_C百科 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not gene
开发者_C百科 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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'
     )
  1. what is b (b.buy_value) ?
  2. FROM portal.gpb_bank_quotes - is that table name? Is it possible that it delimited with .
  3. ahhh too difficult ///

Thanks in advance


  1. b is a table alias for portal.gpb_bank_quotes. This is handy so that you don't have to type portal.gpb_bank_quotes.buy_value, etc.

  2. Yes. portal is a schema, and gpb_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';
0

精彩评论

暂无评论...
验证码 换一张
取 消