I gave up on getting a single SQL to do this; I don't think it's possible?

Guys
I asked a little while ago about a loyalty points system where the loyalties could not be revoked once awarded, so any refunds would make the points system "go into debt" internally and only start issuing loyalty points when the debt was cleared. Got an excellent SQL to do just that, and then they switched requirements on me.
Now, loyalty points can be revoked at any time. It might be that on the 10th Sept a refund transaction dated in MARCH will be inserted that effectively wipes some loyalty points off the balance.. So I'm thinking that I have to mark transactions with a date of when they were used to create (or revoke) points
I'm wondering if someone will sense check my logic and confirm that there isnt a way to do this with read-only SQLs:
An UPDATE query runs, looking for transactions that have not already participated in the points scheme (points_date is null), and meet certain criteria, and setting their points_date to the current trunc(sysdate) -- this ensures that a transaction inserted in retrospect (i.e. inserted long after the date the transaction occurred) will have an effect on points
An hour later a select query runs on all transactions that have a points_date that is not null, grouping up by the card number (cards earn points) and the value of all transactions is summed. Transactions are classed according to their points_date; those that have a points_date before today contribute to the previous_total_spend and all transactions contribute to the current_total_spend. Because there is 1 point for every $10 spent, the amounts are divided by 10, and then FLOORed/CEILed to provide a quantized representation of the number of points a card had yesterday and what is has today. The delta of the number of points from previous to current represents the number of points that should be awarded or revoked.
I have to sum all transactions for all time rather than just do a simplistic "divide every tran by 10 then floor and thats the number of points" because customers who always spent 9.99 wouldnt accumulate any points ever when the should be entitled to one point upon their second purchase (taking their spend to 19.98)
Here's an example code for you to play with; can someone check I've got this right/the maths is robust and if there was a way to do this in a one-step SELECT without the update (I don't see how retrospective transactions could be included properly) let me know?
with t as(
select '20090301' as points_date, 15 as tran_amt, '1234' as card_num from dual
union all
select '20090302' as points_date, 11 as tran_amt, '1234' as card_num from dual
union all
select '20090303' as points_date, 15 as tran_amt, '1234' as card_num from dual
union all
select '20090304' as points_date, 42 as tran_amt, '1234' as card_num from dual
union all
select '20090305' as points_date, 84 as tran_amt, '1234' as card_num from dual
union all
select '20090306' as points_date, -14 as tran_amt, '1234' as card_num from dual
union all
select '20090307' as points_date, 10 as tran_amt, '1234' as card_num from dual
SELECT
  card_num,
  spend_today,
  spend_before,
  spend_today/10 as points_today,
  spend_before/10 as points_before,
  CASE
    WHEN spend_today < 0 THEN
      CEIL(spend_today/10)
    ELSE
      FLOOR(spend_today/10)
  END as quantized_points_today,
  CASE
    WHEN spend_before < 0 THEN
      CEIL(spend_before/10)
    ELSE
      FLOOR(spend_before/10)
  END as quantized_points_before,
  CASE
    WHEN spend_today < 0 THEN
      CEIL(spend_today/10)
    ELSE
      FLOOR(spend_today/10)
  END -
  CASE
    WHEN spend_before < 0 THEN
      CEIL(spend_before/10)
    ELSE
      FLOOR(spend_before/10)
  END as quantized_points_delta
FROM
    SELECT
      card_num,
      SUM(TO_NUMBER(tran_amt)) as spend_today,
      SUM(CASE WHEN points_date < '20090307'--TO_CHAR(sysdate, 'YYYYMMDD')
            THEN TO_NUMBER(tran_amt) ELSE 0 END) as spend_before
    FROM
      t
    WHERE
      points_date IS NOT NULL and
      points_date <= '20090307'--TO_CHAR(sysdate, 'YYYYMMDD')
    GROUP BY
      card_num
  ) totsBy changing the hard coded dates (will be based on report run date when live) you can simulate days passing..
Thanks in advance for any wisdoms

Well I'm leaning the other way. I think my present MBP will be the last Apple product I buy.
With the way Apple is going, all New Mac computers are sealed unit that don't allow the user to upgrade them in any way. They are getting more expensive initially. They are impossible to fix, even by Apple. All the parts are either soldered to the Logic Board or glued inside the case parts. The add on warranty only covers manufacturing defects and is expensive. And to fix one out of waranty is close to if not more then a new system.
The only thing different in a Mac, and most other products Apple sells, is the operating system and the cases they come in. As for the OS both have their glitches and at this time there are no viruses that infect OS X. There is more software available for Windows. More choices as to what hardware you can use or upgrade to at a later date.
Mac computers are becoming large iPads or iPhones with built in keyboards.
jeremy_from_rome wrote:
And as for the question: PC or Mac, the consensus that I hear from colleagues and friends is just as you state it: stay with Mac, be patient, work at it, and you’ll never look back! Thanks again

Similar Messages

  • The battery of my macbook died in 2 years and when I call an inform them Mr ********** (sr advisor) gets outrightly rude and tells me sorry but don't think that you can be an exception to it. Extremely shocked at this approach by apple.

    The battery of my macbook died in 2 years and when I call the servise center to inform them cuse i personally am dissapointed but at the same time want to know the reason why something like this has happened ith a product of apple. Mr ****** (sr advisor) gets outrightly rude and tells me sorry but don't think that you can be an exception to it. Extremely shocked at this approach by apple. Then throughout the conversation he chose to mute me and wouldnt answer my queries. And when i asked him whos the serior I could talk to. He tells me "Im the seriormost that you can get upto..there is nobody above me you can talk to".
    Now what do i do???
    <Edited by Host>

    By doing so, you are violating the terms of use of this support forum
    "Post constructive comments and questions. Unless otherwise noted, your Submission should either be a technical support question or a technical support answer. Constructive feedback about product features is welcome as well. If your Submission contains the phrase “I’m sorry for the rant, but…” you are likely in violation of this policy."
    "Breach of the Agreement
    If you fail to abide by these terms Apple may remove your submission. Apple may also send an e-mail that informs you that your Submission has been deleted or edited. Repeated inappropriate Submissions may result in your relevant account or accounts being placed into temporary or permanent suspension of your ability to participate in any or all of the areas on the Site."
    https://discussions.apple.com/static/apple/tutorial/tou.html

  • How to SUM two count(*) values in a single sql tatement?

    How can I get a single SQL statement to sum two values from a count(*)
    I want something like this:
    SELECT COUNT(*) FROM MYTABLE
    UNION
    SELECT COUNT(*) FROM MYOTHERTABLE;
    but instead of getting
    111
    222
    I want to see the sum of the two values.
    333can such a thing be done with one statement. I know I can do stuff inside a BEGIN END and have vars but wonder if there is simple single statement solution.
    Thanks in advance,
    David Miller

    SQL> select count(*) from user_indexes;
                COUNT(*)
                      30
    SQL> select count(*) from user_tables;
                COUNT(*)
                      43
    SQL> select (select count(*) from user_indexes) + (select count(*) from user_tables)
      2  from dual;
    (SELECTCOUNT(*)FROMUSER_INDEXES)+(SELECTCOUNT(*)FROMUSER_TABLES)
                                                                  73

  • How to get a single row column from a viewobject in java?

    I have a class file that goes out and gets a viewobject and sets its where clause
    this is it:
    vcRow = vc.createViewCriteriaRow();
    vcRow.setAttribute("LogonId", "='" + strPcis_Login.toUpperCase() + "'");
    vc.addElement(vcRow);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    I know this working cause I can watch it in debug..
    but now the problem.
    I've looked in the docs and don't see how one can pull the value of the row it found and place it in a uix page in a textinput area
    how can I get a single row column, in this case the UserName that is in the view object to a string and then place it into my
    uix page? I've looked and looked and don't see a method for this.
    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented?

    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented? What you can do is get the value from your VO and set it somewhere that UIX can data bind to -- as a Page proprety, on HttpSession, etc. This is documented in Chapters 4 (Data Binding) and 5 (Controller) of the UIX Developer's Guide.
    To set a property, you use Page.setProperty(String key, String value). Then, in your UIX file, to make a textInput that has the value pulled from a given page property, use:
    <textInput data:text="key@ctrl:page" />
    -brian
    Team UIX

  • Where else to get help if no responses on this forum?

    Hi All,
    I posted a thread a couple of days ago without response (subject: ORA-20001: get_dbms_sql_cursor error ORA-01747: invalid user.table.column). If no help is forthcoming through this forum, what are other avenues I can pursue to get assistance?
    Thanks,
    Kristina

    Good afternoon Kristina,
    I don't think you are getting no responses because people are just ignoring you. For APEX issues, this is the place for answers. I believe that the issue might be that everyone that looks at your question may think that it is more of a SQL or PL/SQL question - when infact, it is an upgrade question.
    I do not have any APEX 4.1 experience so I can only speak to generalities. However, I would suggest that you might want to make sure that all of the access rights are the same for your 3.1 application and your 4.1 application.
    Did you convert into a new database? or in place? If a new database, you may need to make sure that APEX_PUBLIC_USER (or whatever user you have designated) has access to all of the tables/views and the like that you are using... and has proper execution rights on stored packages, functions and procedures.
    I realize that this should seem a very simplistic answer, but again, having no experience with APEX 4.1, it is all that I can offer.
    I hope this helps. If not, I hope that my response can at least prompt those that might know to go back and review your [url https://forums.oracle.com/forums/thread.jspa?threadID=2333915&tstart=60]original post.
    Good luck,
    Don.
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! :)

  • Running Multiple SQL in a Single Worksheet: Can I Selectively Run a Single SQL and Append Output?

    In any release of SD, if I have a single worksheet containing 10 sqls. Is it possible to place the cursor on any of the sql and run only that sql, yet, append its output to existing output window. I can then select another sql and execute it and keep appending output. In other words, do not clear existing output or start a new output tab.
    As it exists today (in any release), I can either 'run script' which does append, but it executes all the sql (non-selective). Alternately, I can 'run statement' to selectively run a single sql, but it will clear the output window (or if pinned), start a new one. None of this is what I want.
    Thank you.

    Select the query you want to run. Execute it via F5. Then highlight the next query and repeat.
    The output will append to the Script Output panel.
    There's no way to get 2 queries to share a grid, unless you were to run them as a single query a la UNION.

  • In single SQL query?

    Hi...
    I need to write one single sql to get execution audit and map stating with all error details using all possible owb audit tables..
    Am new to the technology..fresher..could any one help me out regarding this query.
    Regards,
    Gautham

    Check this
    find mapping of particular pf?

  • Can this be done using a single sql......

    Hi,
    I have a problem to solve an was just wondering if it was possible to do it using a single sql. It is not imperative that I use a single sql but would like to know if it were possible and if so how, else I would appreciate if I was guided in the general direction where I may be able to find a solution....
    1) Esstentially in this example an employee can have 3 types of managers 'A' 'B' or 'C'.
    2) the emplyee must have 1 and only 1 manager of type 'A' (it is imperative that an emp have a manager of type A)
    3) the employee can have multiple managers of Type B and C but it is possible that the emp does not have any manager of type B and C
    We need a report which compares all the type B managers of an employee to the type A manager of the same employee and if any one of the Type B manager is same as the type A manager then the report indicates 'Equal' else the report indicates 'Not Equal'. if there is no type B manager for the employee then the report should show is as 'Not Equal'.
    The same comparsion need to be done between type C and type A managers for the employee...
    here are the scripts you would require to create a dummy table with data
    ?SCRIPTS START?
    create table emp (empid number(3), mgrid number(3), mgr_type varchar2(1))
    insert into emp values (1,3,'A')
    insert into emp values (1,10,'B')
    insert into emp values (1,14,'C')
    insert into emp values (2,15,'A')
    insert into emp values (3,10,'A')
    insert into emp values (3,10,'B')
    insert into emp values (3,10,'C')
    insert into emp values (4,12,'A')
    insert into emp values (5,2,'A')
    insert into emp values (5,2,'B')
    insert into emp values (5,3,'B')
    insert into emp values (6,1,'A')
    insert into emp values (6,5,'C')
    select * from emp
    ?SCRIPTS-END?
    EMPID> MGRID> M
    1> 3> A
    1 > 10 > B
    1 > 14 > C
    2 > 15 > A
    3 > 10 > A
    3 > 10 >B
    3 > 10> C
    4 >12 > A
    4 > 12 > C
    5 > 2 > A
    5 >2 > B
    5 > 3> B
    6 > 1 > A
    6 > 5 > C
    6 > 7 > C
    Expected Report
    emp_id>     mgr_type_A>     mgr_type_B>     mgr_type_C
    1>>>     3>>>          Not Equal>>>     Not Equal
    2>>>     15>>>          Not Equal>>>     Not Equal
    3>>>     10>>>          Equal>>>          Equal
    4>>>     12>>>          Not Equal>>>     Equal
    5>>>     2>>>          Equal>>>          Not Equal
    6>>>     1>>>          Not Equal>>>     Not Equal
    at the end of the day the report is to be exported as an xls. I would be using java to connect to the DB and create the xls. Obv I could run a simple sql and do a lot of comparision in java and get the desired report... What I am looking for is
    - Is it possible using a single sql.
    - if not.. is it better to use a pl/sql procedure or do it using java code.
    the table has abt 100,000 records .... performance is not really a factor right now...
    I just have no idea where to look.. I thought of pivot tables but could not find a solution... thought of decode as well... but again to no avail... (i am not oracle expert by any means....)
    Appreciate any help I can get...
    Thanks...
    PS: Have used > to seperate the data.. since the preview of the post was truncating all spaces between the columns and was making it difficult to differetiate the data....
    ooooppppsss....just realised i should have put this in the PL/SQL forum.. dont' seem to find an option to delete the post.. so if someone can move it to the other forum... it would be great....
    Message was edited by:
    user520267

    Well, there are no moderators here, so you are going to have to get your answer here :-). Most of us that hang out in PL/SQL are here too.
    Assuming that 4>>> 12>>> Not Equal>>> Equal is a typo because there is only one record for empid 4, this works. There may be more efficient ways but ...
    SQL> SELECT a.empid, a.mgrid,
      2         NVL((SELECT 'EQUAL' FROM emp b
      3             WHERE b.empid = a.empid and
      4                   b.mgrid = a.mgrid and
      5                   b.mgr_type = 'B'), 'NOT EQUAL') bmgr,
      6         NVL((SELECT 'EQUAL' FROM emp c
      7             WHERE c.empid = a.empid and
      8                   c.mgrid = a.mgrid and
      9                   c.mgr_type = 'C'), 'NOT EQUAL') cmgr
    10  FROM emp a
    11  WHERE mgr_type = 'A';
         EMPID      MGRID BMGR      CMGR
             1          3 NOT EQUAL NOT EQUAL
             2         15 NOT EQUAL NOT EQUAL
             3         10 EQUAL     EQUAL
             4         12 NOT EQUAL NOT EQUAL
             5          2 EQUAL     NOT EQUAL
             6          1 NOT EQUAL NOT EQUALYou can format your code and data, as I did here, by using [ pre ] and [ /pre ] without the spaces around the text you want preserved. [ code ] and [ /code ] works too.
    HTH
    John

  • Single SQL call for both Report & Chart

    Hi everyone,
    I am pretty new to APEX and I am loving it :)
    I need to create a page with two region (SQL Report & Flash Chart) and both region data will come from identical SQL statement.
    Could I make them both get data from a single sql call, instead of making 2 identical sql call for each region?
    Thanks before for any help.

    Can't think of any practical way to use only one call. Best I can come up with it to create the query as a Shared Component. At least that way your using the identical SQL source.
    HTH
    Chris

  • Performance/costs improvements from single SQL database to elastic scale

    Hi there!
    I already posted a previous question on whats the best way to setup a elastic scale architecture for our application(https://social.msdn.microsoft.com/Forums/azure/en-US/82fabac7-137b-46d6-a9f0-5e71e4bbc9eb/using-datadependent-routing-in-combination-with-membership-provider?forum=ssdsgetstarted).
    The next thing we need to know before we can implement elastic scale is if this is really going to help us with our performance and costs where we experiencing problems at the moment.
    Currently we have a single SQL database(p3 800 DTU's).
    We have run queries against our database which can calculate the number of DTU's we need to get good performance for that database.
    My questions are:
    1.When we implement elastic scale, can we really improve our performance and can this lead to saving costs on SQL databases?
    2. Is there maybe a way we can easily test this by running queries or setting up an environment  where we can see real differences in DTU's per Shard?
    Thanks!

    Hi Elmar,
    If you're already hitting performance limits with your P3 database, other than upgrading to the
    new V12 server for improved premium performance, that is the highest you can currently vertically scale.  Thus, it becomes advantageous to scale out to achieve better performance. 
    A small caveat, my answers below are really contingent upon your workload, query patterns, and sharding scheme.
    1.When we implement elastic scale, can we really improve our performance and can this lead to saving costs on SQL databases?
    Absolutely.  If you look at the table below, you can see the ~Cost per DTU/month. For a P3 you are paying $4.65/DTU/month.  If you were to scale out, with the same number of DTUs on an S2, for example, you'd achieve an 67% savings on
    cost for the same number of DTUs (800).  Please keep in mind that there are feature differences between Standard and Premium SKUs as well as total size (250GB vs 500GB) - these may or may not affect your application.
    **Please note that S3 above is the preview price (50% off).
    2. Is there maybe a way we can easily test this by running queries or setting up an environment  where we can see real differences in DTU's per Shard?
    The available DTUs per shard is a constant value.  In principle, 800 DTUs on one P3 database is equivalent in performance capacity of 100 DTUs on eight P1s.  The test you want to perform is a comparison between your scale-up
    solution versus a scale-out solution as perceived by both the database %DTUs consumed and the response time/throughput of your client application. 

  • Compare and insert in single SQL

    Hi ,
    I want to insert data from one source table to destination table based on the condition that a row does not exist in destination table based on some column filter . Is it achievable using single SQL.?
    Merge statement cannot be used as there is no unique key in source table and destination table.
    Here is the data and tables.
    create table test_source
    x_id number,
    report_sent_flag varchar2(30),
    year number
    insert into test_source
    select 10 , 'Y' , 2013 from dual
    union all
    select 20 , 'Y' , 2013 from dual
    union all
    select 30 , 'Y' , 2013 from dual
    union all
    select 10 , 'Y' , 2013 from dual
    union all
    select 20 , 'Y' , 2013 from dual
    union all
    select 30 , 'Y' , 2013 from dual;
    create table test_dest
    x_id number,
    report_sent_flag varchar2(30),
    year number
    insert into test_dest
    select 10 , 'Y' , 2013 from dual
    union all
    select 10 , 'Y' , 2013 from dual;
    select * from test_source  ;
    10    Y    2013                                            
    10    Y    2013
    20    Y    2013
    20    Y    2013
    30    Y    2013
    30    Y    2013
    select * from test_dest ;
    10    Y    2013
    10    Y    2013
    Now , i need compare test_source and test_dest tables on column  (x_id , report_sent_flag and year ) column , since 10 , Y , 2013 is present in test_dest , it will be skipped . Rest should get inserted into test_dest table from test_source.
    Can it done by SQL only ?
    Please assist
    Thanks
    Please assist

    only SQL :
    SQL> select * from test_source  ;
          X_ID REPORT_SENT_FLAG                     YEAR
            10 Y                                    2013
            20 Y                                    2013
            30 Y                                    2013
            10 Y                                    2013
            20 Y                                    2013
            30 Y                                    2013
    6 rows selected
    SQL> select * from test_dest ;
          X_ID REPORT_SENT_FLAG                     YEAR
            10 Y                                    2013
            10 Y                                    2013
    SQL> select * from log_exists_records;
          X_ID REPORT_SENT_FLAG                     YEAR
    SQL>
    SQL> insert into log_exists_records
      2  select * from test_source
      3  where (x_id,report_sent_flag,year ) in (select x_id,report_sent_flag,year from test_dest)
      4  /
    2 rows inserted
    SQL>
    SQL> insert into test_dest
      2  select * from test_source
      3  where (x_id,report_sent_flag,year ) not in (select x_id,report_sent_flag,year from test_dest)
      4  /
    4 rows inserted
    SQL> select * from test_source  ;
          X_ID REPORT_SENT_FLAG                     YEAR
            10 Y                                    2013
            20 Y                                    2013
            30 Y                                    2013
            10 Y                                    2013
            20 Y                                    2013
            30 Y                                    2013
    6 rows selected
    SQL> select * from test_dest ;
          X_ID REPORT_SENT_FLAG                     YEAR
            20 Y                                    2013
            30 Y                                    2013
            20 Y                                    2013
            30 Y                                    2013
            10 Y                                    2013
            10 Y                                    2013
    6 rows selected
    SQL> select * from log_exists_records;
          X_ID REPORT_SENT_FLAG                     YEAR
            10 Y                                    2013
            10 Y                                    2013
    SQL>
    Ramin Hashimzade

  • Executing multiple sql statements from a single sql file

    Hi, I am Vijay Krishna.
    I want to drop user, drop tablespace, create tablespace and create user from a single executable file or a single sql file. The command should be in sequence. How can we achieve it? Can I anybody help me in this regard. I want this as soon as possible. It's urgent. Kindly post a reply.
    Also, how can we know the oracle home directory from a java program? The problem is we should know the Oracle home directory and use it for creating the tablespace. In the userinterface we will give just for a new database user creation. I will be really thankfull if anybody can help me in this regard.

    It is showing any error messages.
    I will diplay the entire batch file which we are using.
    sqlplus / as sysdba
    drop user examination cascade;
    drop tablespace examination;
    create tablespace examination
    datafile 'C:\oracle\product\10.1.0\oradata\orcl\examination.dbf'
    size 500M autoextend on;
    create user examination identified by examination
    default tablespace examination
    quota unlimited on examination;
    grant connect, resource to examination;
    exit;
    when i run the batch file from the DOS prompt it is entering into the sql prompt and coming out in a fraction of a second. We are just seeing a screen coming and going. But no error messages are being displayed.
    first we thought that as we are giving the create tablespace and create user in the same file we created another file and tried without having the create commands. Even then the user didn't get dropped.

  • Update two different tables by a single sql query:

    Hi All,
    i need to update two different talbes in a single sql query..
    i m using the following query
    UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
    AND
    UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    i m getting the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
    SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    but when i m ushin the same query in Microsoft SQL Server it executes properly:
    please help me out...

    Duplicate thread. I've already answered on your other thread...
    update two different tables by a single sql query:

  • Single SQl Query with different where conditions

    Experts,
    I have a requirement to design a report. Here are the details
    I have Report table layout
    Profit center Gross sales (This Year) Gross Sales (Last Year) % change Year of Year
    The Report has a selection of entering the Start Date.
    I have a single table in oracle which has profit center and Gross Sales Values on daily basis.
    I want to write a single sql query to calculate both Gross Sales current year and Gross Sales Last Year. I can calculate Gross Sales Current Year by putting the where condition for start date = Current Year Date which i pass through report. I want to calculate the Gross Sales Last Year in the Same query by putting the different where condition i.e start date = Last Year date based on the date input.
    I dont know how to put two where conditions in single query for two different columns.
    Any help will be appreciated.
    Thanks in advance
    Regards
    Santosh

    instead of changing your where clause couldn't you just determine the yearly totals from your table and then use the lag statement to get last years total?
    something like this?
    I just made up 10,000 days worth of sales and called it fake table it is supposed to represent a variant of the table you were describing as your base table.
    with fake_table as
    ( select trunc(sysdate + level) the_day,
    level daily_gross_sales
    from dual
    connect by level < 10001
    select yr, year_gross_sale, lag(year_gross_sale) over (order by yr) prev_year_gross_sale,
    (year_gross_sale - lag(year_gross_sale) over (order by yr))/year_gross_sale * 100 percent_change
    from
    (select distinct yr, year_gross_sale from
    select the_day,
    daily_gross_sales,
    extract(year from the_day) yr,
    extract(year from add_months(the_day,12)) next_yr,
    sum(daily_gross_sales) over (partition by extract(year from the_day)) year_gross_sale
    from fake_table
    order by yr
    )

  • How to split numbers in a string with a single SQL on 10.2?

    Is it possible to to below action with a single SQL on 10.2?
    input > '3abc4de5f'
    output > '3,abc,4,de,5,f'
    Thank you.

    It might be a NLS issue. Follow the suggestion of Karthick_Arp and use [[:alpha:]] instead:Is is
    SQL> with t as (select 'a' l from dual union all
               select 'b' l from dual union all
               select 'A' l from dual)
    select * from t
    order by nlssort(l, 'NLS_SORT=GERMAN')
    L
    a
    A
    b
    3 rows selected.
    SQL> with t as (select 'a' l from dual union all
               select 'b' l from dual union all
               select 'A' l from dual)
    select * from t
    order by nlssort(l, 'NLS_SORT=DANISH')
    L
    A
    a
    b
    3 rows selected.You could also do a case insensitive match (As in TXT3)
    SQL> alter session set NLS_SORT=DANISH
    Session altered.
    SQL> with t as (select 'aADSFF3332abc4342de5Df' txt from dual
               union all
               select '3abc4de5f' from dual)
    select txt, regexp_replace(txt, '([0-9]{1,}|[a-z]{1,})', '\1,') txt2
               ,regexp_replace(txt, '([0-9]{1,}|[a-z]{1,})', '\1,', 1, 0, 'i') txt3
      from t
    TXT                            TXT2                           TXT3                         
    aADSFF3332abc4342de5Df         a,ADSFF,3332,abc,4342,de,5,Df, aADSFF,3332,abc,4342,de,5,Df,
    3abc4de5f                      3,abc,4,de,5,f,                3,abc,4,de,5,f,              
    2 rows selected.
    SQL> alter session set NLS_SORT=GERMAN
    Session altered.
    SQL> with t as (select 'aADSFF3332abc4342de5Df' txt from dual
               union all
               select '3abc4de5f' from dual)
    select txt, regexp_replace(txt, '([0-9]{1,}|[a-z]{1,})', '\1,') txt2
      from t
    TXT                            TXT2                         
    aADSFF3332abc4342de5Df         aADSFF,3332,abc,4342,de,5,Df,
    3abc4de5f                      3,abc,4,de,5,f,              
    2 rows selected.Regards
    Peter

Maybe you are looking for