Add column according to date

Hello

I want to add column as from Time_period conditon below

If the review date is between the date of yesterday for a week, then it should display as "week1.

If the review date is 2nd week, then it should display as "semaine2" and so on.

I tried, but do not get the correct result.

Can someone help me.

Thank you

with abc as

(select 101 as id, to_date('21-JUL-2015','DD-MON-YYYY') as double union review

Select 102, double union to_date('17-JUL-2015','DD-MON-YYYY')

Select 103, to_date('13-JUL-2015','DD-MON-YYYY') of double union

Select 104, to_date('12-JUL-2015','DD-MON-YYYY') of double union

Select 105, double union to_date('01-JUL-2015','DD-MON-YYYY')

Select 106, to_date('01-JUN-2015','DD-MON-YYYY') of double union

Select 107, to_date('29-JUN-2015','DD-MON-YYYY') of double union

Select 108, to_date('07-JUL-2015','DD-MON-YYYY') of double union

Select 108, double to_date('03-JUL-2015','DD-MON-YYYY')

)

SELECT id,

-case when trunc (review) between trunc (sysdate)-1 and trunc (sysdate)-7 then "week1.

When trunc (review) between trunc (sysdate)-8 and trunc (sysdate)-15 then 'semaine2 '.

When trunc (review) between trunc (sysdate)-16 and trunc (sysdate)-23 then "week3.

Another 'other '.

end as Time_period

ABC

Hello

You must provide the lower date first in your between the declaration

-case when trunc (review) between trunc (sysdate)-7 and trunc (sysdate)-1 then "week1.

When trunc (review) between trunc (sysdate)-15 and trunc (sysdate)-8 then 'semaine2 '.

When trunc (review) between trunc (sysdate)-23 and trunc (sysdate)-16 then 'week3.

Concerning

Marcus

Tags: Database

Similar Questions

  • Is it possible to add columns to explore details view customization

    Under XP it is possible to add columns for Windows Explorer details columns that are not the default choice?  I want to add a column "written by" and "reviewed by" and preferably have the name of the preparer (or reviewers) or initials and a date stamp

    Hello

    I suggest you to post your query in development issues General Windows Desktop for better eon helps the concern: http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads

  • ALTER TABLE hf_altertest ADD COLUMN does not

    I am using ORACLE 11g and my FDI is Developer SQL 4.1.1

    It's all free PC version that has limits.

    I tried on:

    CREATE TABLE hf_altertest

    (

    contact_id INTEGER NOT NULL

    , name VARCHAR (25)

    , last_name VARCHAR (35)

    PRIMARY KEY (contact_id)

    );

    ALTER TABLE hf_altertest State to add a CHAR (2) COLUMN;

    But when I go to run the ALTER TABLE statement then I get following error:

    rror starting at line: 1 323 in command.

    ALTER TABLE hf_altertest State to add a CHAR (2) COLUMN

    Error report-

    SQL error: ORA-00904: invalid identifier

    00904, 00000 - '% s: invalid identifier '.

    * Cause:

    * Action:

    I can run the same code in MySQL without error.

    This leads me to think that maybe I'm just bumping into a limit in the free version of PC.

    Any thoughts?

    3003916 wrote:

    I am using ORACLE 11g and my FDI is Developer SQL 4.1.1

    It's all free PC version that has limits.

    ALTER TABLE hf_altertest State to add a CHAR (2) COLUMN;

    But when I go to run the ALTER TABLE statement then I get following error:

    rror starting at line: 1 323 in command.

    ALTER TABLE hf_altertest State to add a CHAR (2) COLUMN

    Error report-

    SQL error: ORA-00904: invalid identifier

    00904, 00000 - '% s: invalid identifier '.

    * Cause:

    * Action:

    I can run the same code in MySQL without error.

    This leads me to think that maybe I'm just bumping into a limit in the free version of PC.

    Any thoughts?

    There is no LIMIT to the 'free' version  If you read the error message he said THAT was not a valid identifier.  Just to show you that I tried your erroneous statement

    ALTER TABLE hf_altertest ADD COLUMN state2 CHAR(2);
    

    and here is the indicator error message in SQL +.

    SQL * more: Production of liberation 12.1.0.2.0 Tue Oct 15 14:34:57 2015

    Copyright (c) 1982, 2014, Oracle.  All rights reserved.

    Connected to:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    With the partitioning, Real Application Clusters, Automatic Storage Management, OLAP

    and Data Mining options

    Add a COLUMN state2 TANK (2)

    *

    ERROR on line 2:

    ORA-00904: invalid identifier

    As you can see (and as the previous poster of response indicates), the 'COLUMN' KEYWORD is not necessary when adding new columns.  Only when 'RENAME' is used, then you add the keyword COLUMN.

    See the documentation for the syntax of ALTER TABLE here--> http://docs.oracle.com/database/121/SQLRF/statements_3001.htm#SQLRF01001

    See specific clause RENAME syntax here--> http://docs.oracle.com/database/121/SQLRF/statements_3001.htm#i2183480

  • Create a join between a column of type DATE and DATETIME RPD

    Hello

    In my DR. I have a fact table with a DATE column, which also contains a component "hour". The physical layer shows this as a DATETIME column that to this DAY, I've changed since I'm only interested in the part of the date.

    When I join it an alias of my Date dimension, the generated sql physics is similar to:

    DIM_DATE. DATE = FACT_A.FINISH_DATE

    What I really want is:

    DIM_DATE. DATE = TRUNC (FACT_A.FINISH_DATE)


    How can I achieve this at the level of the RPD? Yes, I can add a new column to the table of DW with truncated value, but I want to know why even though I chose the DATE as the type of data to the RPD, the created join does not have a trunk.


    Thank you


    Manish

    The physical layer shows this as a DATETIME column that to DATE, I have changed since I was only interested in the part of date.

    N ° bad idea. The physical layer of the RPD should show what the physical source. So if it isn't a DATE, don't pretend OBIEE is it. For the exact reason that you now - tap you are pregnant OBIEE to write some SQL magic to cast the data type, without even say things which is the original type. OBIEE will not interrogate the metadata in order to check the data types in the source, it will rely on what you tell it in the physical layer.

    How can I achieve this at the level of the RPD?

    You could use an inline view in the physical layer and make your trunc here I guess. Better, as you've already identified, is to store the date as a date if this is going to be a key column to reach.

    I want to know why even though I chose the DATE as the type of data to the RPD, the created join is not a trunk.

    See above. OBIEE does not know it is a DATETIME value, then why would he do a TRUNK?

  • Add columns

    Hi all

    11g.2 Oracle under OL 5.6

    I must add column in my paintings like the below:
    desc x ;
    id 
    name 
    sal 
    
    i want to add column comm 
    
    desc x;
    id 
    comm
    name
    sal
    in fact we have tables that hold the CDRs, but today I found the CDRs not uploaded in the database because of the team IN to increase the columns in the table
    We have a 40 column but it became 41 and the added column life team in position 32.
    so I need to know how to do to add the column in the middle of my table without re-creating the table again (contain data).


    Thank you

    I don't think there is any direct sql command to do so. But you can do something for this. This link will help you:

    http://www.orafaq.com/FAQ/how_does_one_add_a_column_to_the_middle_of_a_table

  • AdvancedDataGrid - add columns with ActionScript

    I am trying to add columns in an AdvancedDataGrid via ActionScript.

    I can't make it work.

    I tried two approaches - with an intermediary table to store the columns then set the adg in table columns; One where I assign columns directly to the table of columns of the adg.

    They are likely to fail in their own way.  The columns don't "take" and the adg uses the default values for dataProviders, or there are no columns at all.

    "adg_test.mxml" has the code AdvancedDataGrids. 

    'adg_test_renderer.mxml' is a rendering engine for one of the columns.

    Would appreciate learning what I'm doing wrong.

    Thanks for any help.

    = Adg_test_renderer.mxml START =.

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:mx mx:VBox ' http://www.Adobe.com/2006/MXML ">
    < mx:Button id = "btnTest" label = "Working Renderer" / >
    < / mx:VBox >

    = Adg_test_renderer.mxml END =.

    == Adg_test.mxml START =.

    <? XML version = "1.0"? >
    < mx:Application
    ' xmlns:mx = ' http://www.Adobe.com/2006/MXML "
    Initialize = "init ()" >

    < mx:Script >
    <! [CDATA]
    Import mx.collections.ArrayCollection;

    [Bindable]
    private var dpADGExplicit:ArrayCollection = new ArrayCollection([)
    {Artist: 'Pavement', Album: 'Slanted and enchanted', price: 11.99},.
    {Artist: 'Pavement', Album: 'Brighten the corners', price: 11.99},.
    {Artist: 'Saner', Album: 'A child once', price: 11.99},.
    {Artist: 'Saner', Album: 'Helium wings', price: 12.99},.
    {Artist: 'The doors', Album: 'The doors', price: 10.99},.
    {Artist: 'The doors', Album: "Morrison hotel", price: 12.99},.
    {Artist: 'Grateful Dead', Album: 'American Beauty', price: 11.99},.
    {Artist: 'Grateful Dead', Album: 'In the Dark', price: 11.99},.
    {Artist: 'Grateful Dead', Album: 'Shakedown Street', price: 11.99},.
    {Artist: 'The doors', Album: 'Strange Days', price: 12.99},.
    {Artist: 'The doors', Album: 'The best of the doors', price: 10.99}
    ]);

    [Bindable]
    private var dpADGActionScript:ArrayCollection = new ArrayCollection([)
    {Artist: 'Pavement', Album: 'Slanted and enchanted', price: 11.99},.
    {Artist: 'Pavement', Album: 'Brighten the corners', price: 11.99},.
    {Artist: 'Saner', Album: 'A child once', price: 11.99},.
    {Artist: 'Saner', Album: 'Helium wings', price: 12.99},.
    {Artist: 'The doors', Album: 'The doors', price: 10.99},.
    {Artist: 'The doors', Album: "Morrison hotel", price: 12.99},.
    {Artist: 'Grateful Dead', Album: 'American Beauty', price: 11.99},.
    {Artist: 'Grateful Dead', Album: 'In the Dark', price: 11.99},.
    {Artist: 'Grateful Dead', Album: 'Shakedown Street', price: 11.99},.
    {Artist: 'The doors', Album: 'Strange Days', price: 12.99},.
    {Artist: 'The doors', Album: 'The best of the doors', price: 10.99}
    ]);

    private function init (): void
    {
    var arr:Array = []; table of //Intermediary which became the AdvancedDataGridColumn table
    var col: AdvancedDataGridColumn = new AdvancedDataGridColumn();

    col.dataField = "artist";
    arr.push (col);

    col.dataField = 'Album ';
    Col.Visible = false;
    arr.push (col);

    col.dataField = "Price";
    col.itemRenderer = new ClassFactory (adg_test_renderer);
    arr.push (col);

    adgActionScript.columns = arr;

    UNSUCCESSFUL ALTERNATIVE APPROACH

    /*
    col.dataField = "artist";
    adgActionScript.columns.push (col);

    col.dataField = 'Album ';
    Col.Visible = false;
    adgActionScript.columns.push (col);

    col.dataField = "Price";
    col.itemRenderer = new ClassFactory (adg_test_renderer);
    adgActionScript.columns.push (col);
    */
    }

    []] >
    < / mx:Script >

    < mx:Label text = "Explicit columns" / >

    < mx:AdvancedDataGrid
    ID = "adgExplicit".
    Width = "100%" height = "100%".
    sortExpertMode = "true".
    dataProvider = "{dpADGExplicit}" >
    < mx:columns >
    < mx:AdvancedDataGridColumn dataField = "Artist" / >
    < mx:AdvancedDataGridColumn dataField = "Album" visible = "false" / >
    < mx:AdvancedDataGridColumn dataField = "Price" itemRenderer = "adg_test_renderer" / >
    < / mx:columns >
    < / mx:AdvancedDataGrid >

    < mx:Label text = "columns ActionScript (ActionScript so works: Arist column should be hidden.)" Should see Album with data columns and price with the buttons. / >

    < mx:AdvancedDataGrid
    ID = "adgActionScript".
    Width = "100%" height = "100%".
    sortExpertMode = "true".
    dataProvider = "{dpADGActionScript}" >
    < / mx:AdvancedDataGrid >

    < / mx:Application >

    == Adg_test.mxml END =.

    If you are looking to add columns with ActionScript, follow this.

    var _advancedDataGrid: AdvancedDataGrid = new AdvancedDataGrid();

    var columns: Array = _advancedDataGrid.columns;

    Columns.push (new AdvancedDataGridColumn ('field1'));

    Columns.push (new AdvancedDataGridColumn ('field2'));

    Columns.push (new AdvancedDataGridColumn ('field3'));

    _advancedDataGrid.columns = columns;

    _advancedDataGrid.validateNow ();

  • Column values of Date on Insert

    HII,

    For a long time we return reported a column data type Date the 10 G version. But now my client want to insert Date with Micro seconds or milliseconds level.

    Y at - it opportunities to do this. This Table contains huge data. If we are not interested to change the column to TimeStamp Data Type.


    Please clarify me on this.


    Thank you
    MohanA Krishna K

    You will need to add another column to your ORDER BY clause to get the right order. If this column already exists in your table, I'm not sure.

  • the value of the xml column type tag data BLOB

    Hello

    I'm on Oracle 10 g.
    I have a table that has a column as BLOB data type and contains XML data. I need to select specific table records according to a unique tag value of the xml data in the BLOB column. For example:
    The table say Test has two columns: id (integer) and MESG (BLOB)
    The xml in the MESG column message is assumed:
    < message >
    < > 123456 contactphone < / contactphone >
    < contactname > ABCD < / contactname >
    < amount > 9999 < / amount >
    < / message >

    I need to extract only the records where the amount is = 9999

    Help, please. Thanks in advance.

    user12850338 wrote:
    Hi BluShadow,
    Thanks for your reply.
    I confess that if we would have used type xml in the first place, things would have been easier.
    For example, I mentioned three tags in the xml file, but my real data contains some hundreds of tags... :( So it will always be a good idea with this approach.

    Yes, it's a good approach. Oracle has provided built-in XML functionality to manage XML, then of course it's the best thing to use. :)

    For example, you can easily deal with namespaces and repeating nested groups and flatten the data in a table structure. for example

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH t as (select XMLTYPE('
      2  
      3    
      4      1
      5      1800
      6      
      7        1
      8        28
      9        6
     10        12
     11      
     12      
     13        5
     14        19
     15        1
     16        90
     17      
     18    
     19    
     20      2
     21      2400
     22      
     23        3
     24        14
     25        7
     26        5
     27      
     28    
     29  ') as xml from dual)
     30  -- END OF TEST DATA
     31  select x.country, x.point, y.user_id, y.target, y.state, y.task
     32  from t
     33      ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
     34                '/RECSET/aa:REC'
     35                PASSING t.xml
     36                COLUMNS country NUMBER PATH '/aa:REC/aa:COUNTRY'
     37                       ,point   NUMBER PATH '/aa:REC/aa:POINT'
     38                       ,user_info XMLTYPE PATH '/aa:REC/*'
     39               ) x
     40      ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
     41                '/aa:USER_INFO'
     42                PASSING x.user_info
     43                COLUMNS user_id NUMBER PATH '/aa:USER_INFO/aa:USER_ID'
     44                       ,target  NUMBER PATH '/aa:USER_INFO/aa:TARGET'
     45                       ,state   NUMBER PATH '/aa:USER_INFO/aa:STATE'
     46                       ,task    NUMBER PATH '/aa:USER_INFO/aa:TASK'
     47*              ) y
    SQL> /
    
       COUNTRY      POINT    USER_ID     TARGET      STATE       TASK
    ---------- ---------- ---------- ---------- ---------- ----------
             1       1800          1         28          6         12
             1       1800          5         19          1         90
             2       2400          3         14          7          5
    
    SQL>
    
  • According to date of directx, I can no longer the game Age of conquest of the Empire.

    Original title: Directx

    According to date of directx, I can no longer the game Age of conquest of the Empire. How can I cancel the update?

    Read the section titled: duration of the DirectX end-user install if your app or game requires an earlier version of DirectX
    https://support.Microsoft.com/en-us/KB/179113

    J W Stuart: http://www.pagestart.com

  • Invalid procedure after alter table add &lt; column &gt;

    Hello Experts,

    I was faced with a situation where I add a column in a table that is used in a procedure, immediately after the addition of the new procedure associated with this table column becomes invalid.

    Can someone explain please know why this happens.

    Database version:-11.2.0.4.

    I was faced with a situation where I add a column in a table that is used in a procedure, immediately after the addition of the new procedure associated with this table column becomes invalid.

    Can someone explain please know why this happens.

    Yes - the Oracle documentation explains this. I found this doc with a simple search of "column, add the oracle 11g invalid procedure.

    http://docs.Oracle.com/CD/B28359_01/server.111/b28318/dependencies.htm#CHDJIIFC

    Table 6-2 , shows how objects are affected by changes to other objects upon which they depend.

    Table 6-2 operations affects this object status

    Operation Where the status of dependent objects

    ALTERTABLEtableADDcolumn

    INVALIDWhen:

    • Uses of the object (except a view)-dependent SELECT * on table .
    • Dependent object uses table %rowtype .
    • Dependent object performs INSERT on table without specifying a list of columns.
    • Dependent object references table in the query that contains a join in SQL.
    • Dependent object references table in the query that refers to a PL/SQL variable.

    Otherwise, no change.

    Read the WHOLE ARTICLE and see if it does not have to explain your problem.

  • Add months to ore.date

    Is it possible to add months on ore.date without ore.pull?

    Example:

    Version 1.4 of ore

    > DATE <-ore.push (seq (also. Date("1999/1/1"), by = "3 month", length = 2)) [2]

    > DATE

    [1] "1999-04-01.

    > class (DATE)

    [1] "ore.date".

    attr(,"package")

    [1] "OREbase".

    >

    > NEW_DATE <-seq (DATE = '3 month', length = 2)

    Error in seq.int (r1$ Lun, by =, length.out = length.out):

    "provenance" should be finished

    Currently the ore.datetime feature to perform aggregates and summaries, comparisons, extract values and constraints.

    In order to modify the datetime object, you can shoot locally using ore.pull:

    DATE<- ore.push(seq(as.date("1999/1/1"),="" by="3 months" ,="" length="">

    Date<->

    new_date<- seq(mydate,="" by="3 months" ,="" length="">

    NEW_DATE<->

    Class (NEW_DATE)

    R > NEW_DATE

    [1] "1999-04-01" "1999-07-01".

    R > class (NEW_DATE)

    [1] "ore.date".

    attr(,"package")

    [1] "OREbase".

    I'll add an improvement to enable this feature for a future version of ore.

    Sherry

  • How to use the transformation script to add columns to the PK?

    I'm working on a script transformation that:
    -create a table
    -Adds the columns to the table
    -create a primary key for the table

    See the below script.
    Now, I want to add the primary key column.
    Documentation fix r: class IndexColumnUsage

    The Index of the class has a getter: getIndexColumnUsageList()
    and the list apply: applyIndexColumnUsageList

    Someone at - it an idea how to use these methods to add the column to the PK?

    I thank in advance.


    relational = model.getDesign () .getFirstOpenRelationalDesign ();
    table = relational.getTableSet () .createTable (null);
    table.setName ("TABLE");
    column = table.createColumn (null);
    column.setName ("COLUMN");
    index = table.createIndex (null);
    index.setName ("PK");
    index.setIndexState ("primary obligation");

    Hello

    If you have the column and index (both belonging to the same table) use:

    the index. Add (Column);

    to remove the column:

    the index. Remove (Column)

    Philippe

  • How to use the script to display the number of columns contain no data

    I have a requirement. There is a source that is the excel, the excel file file, we need to load data into the staging table. There are 5 columns mandatory ones must not be null. We used "No. Data Check" for this. The logic is so mentioned previously mentioned 5 columns don't contain any record that the record will be moved to without data. So far, it is fine. Now the requirement is to show what column or columns contain no data. We used a script to do this like:

    RES =' '

    RES = input1 [0] + ": failed because values null in required columns;"

    INPUT1 [1] = res;

    Output 1 = res;

    But it shows message "down because of nulls in the required columns", which is a generic message. We must show what column or columns does not contain the value "failed because of null values in a column required columnA, columnB or columnC. Can someone help me in this regard. Any kind of help is appreciated.

    You can use the variable inputname1, which keeps an array of names of the entry for the script processor attribute. For example:

    var result = "";

    var first = true;

    for (i = 1; i< input1.length;="" i++)="">

    If (input1 [i] == null | input1 [i] == ' ') {}

    If {(first)

    Firstly = false;

    } else {}

    result += "";

    }

    lead inputname1 += [i];

    }

    }

    If (result.length > 0) {}

    result = "failed due to null values in the following mandatory columns:"+ result; "

    }

    Output 1 = result;

    Kind regards

    Nick

  • 2 writers can add to the same data staged?


    Hello

    How can we get 2 entries to write on the same data staged without data loss? I need to write the rejected records to a staging of data in 2 different processes before exporting.

    Kind regards

    Ravi

    No, you can not do this. Ecrire write to different sets of data on stage, then use a process with the merge data stream to bring together them.

    Otherwise, use two different sets of data staged or data interfaces and add to export. Data interfaces means that you never staged. The staged data: you can choose whether or not to step in the configuration of the task (or run profile).

  • How can I add days to a Date value in a Script time?

    How can I add days to a Date value in a Script (XPATH) time?

    XPATH:

    Add Date:

    xs:dateTime($yourCurrentDateVar) + xs:dayTimeDuration($yourDuration)
    

    Difference in date:

    move "fn:days-from-duration(xs:dayTimeDuration(xs:date($yourCurrentDateVar) - xs:date($yourPrevDateVar)))" to $diff;
    

    You did not mention the version of the Framework, you can take advantage of the Business Service (BS) to perform Date calculations, for example, for FW2.2.x, you can use BS: C1-DateMath with such options as the 'Resistance' to add to the Date, "DIFF" for Date-Diff and FW4.x, you can use BS: F1-DateMath with options such as "F1AD" to add to the Date etc.

    Find out more about XPATH herefunction.

Maybe you are looking for

  • 13 stream: Stream HP 13 laptop

    HP 13 Stream relatively new with only MS Office and all the files in the cloud.   8.1 (64-bit) Windows operating system.  System couldn't be any simpler or cleaner. The disk hard retains complete on its own?  I've reformatted twice, and I have nothin

  • I'm looking for a version of firmware of a new Camileo

    Hello everyone in this forum. I have this nice (with 5.2 CMOS) camcorder for five months, and I was wondering if a new firmware relase is available or not.I experienced a few problems using this device as MP3 player: (1) the "navigation in folders" i

  • Find physical limits without limit switches.

    Hello I have a mechanical system which is operated by a motor without Stricker of CC of enslavement. It is a very small system and close is not possible to place the micro swithces in it. But I must find its limits before and back. How can I find its

  • How to get the license for Norton Security software?

    Original title: license norton. I think that I have norton on my laptop, as every time I download a file, it tells me or tells me its safe. It must have been with my laptop. the safety of the trial of norton on my phone has expired and he asked me to

  • DLLEXPORT, DLLSTDCALL and the two