oracle - SQL Query from list of strings -


I am trying to query the last time I imported from a SQL table "Import", one month's string integer January '01', '02' is' 02 ', March is 03'.). I have pasted my solution below, but I was thinking that there is another great way to do this. Select imported month (month month month month month month month month) (choose the month of '01' month from dual union 'select two months' Select month from dual union '' 03 '' Dual union of the month Select 'duration' month from dual union '05' month_string Select from dual union '06' month_string Select from dual union '07' month select from the stringing dual union '08' month_ select from franchise double association ' 09 'month_strain double Select from Union from 'Double Month' String 'Select' from Dual Union '11' Months of Months Selecting month of '12' month month) Where the import Prokosm_moth (+) = months Month_string group for months For months.

I do not know that you will get this more "elegant", but here's a better To type method query:

  select months.month_string, max (import.process_date) from ('01' double union select all '02' from month_string as dual to month_string As the selection union dual union dual union all select '05' from month_string as select from all '04' to month_string as' select all '03' dual from dual to dual union dual dual form D Select all '07' to month_string as selection of '06' as the month_string of union Dual union dual union all selected as '10' to month_string as selection of '09' to month_string All select '08' as dual to month_string as Dual Union Dual Union Select all '12' to month_string as 'Select all 11' to month_string) Import the left over in the months import on import. Process_moth = months Months by month_string group Order from months Month_string;  

Changes are here.

  • Oracle syntax for reciprocity (uninterpretable) external joins with a clear, ANSI standard external join
  • Reversed the order of tables, reversed a left external participants instead of correct external support .
  • Change different to select . specific select group
  • is not required for almost << code> union to union all . . union , spends an attempt to remove duplicates, which is not necessary.
  • Added like to column aliens makes it clear that name is being assigned to the column, and helps Quam to stop deceptive commas.

You can also connect to or the recursive CTE to actually generate the number of months, but I'm not sure that this version It will be clear.

Edit:

I was making this assumption that you should get the NULL values ​​because in all the months import < / Code> This is the reason why you will use a month table if not, then just do it:

  select i.process_month, max (I.process_date) imported by i.process_month by group i.process_month command;  

If you are concerned about the limit, then select

  i.process_month, Max (i.process_date) from import into where i. Process_month ('01', '02', '03', '04', '05', '06', '07', '08', '09 ',' 10 ',' 11 ',' 12 ') .process_month command by i.process_month;  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -