SQL function to retrieve records only if all values are available.

Hello

I have a sales table on which I run a parameter query.

We spend a few IDs of the week to recover in-store sales.

I need to retrieve only the stores that has sales in all the IDS of the past week.

If I use the in operator, I get the data from the store even if there is a sale for only one week.

Is there a function for this oracle?

Thank you
Sharan.

Hi, Sharan,

Here's how you can use analytical COUNT:

WITH     got_week_cnt     AS
(
     select  week_id, store_id, prod_desc, sales_units_raw, sales_value_raw
     ,     COUNT (DISTINCT week_id) OVER (PARTITION BY  store_id)            AS week_cnt
     from     sales_store_dwh
     where      week_id in (&&Week_ID_CSV)
)
select  week_id, store_id, prod_desc, sales_units_raw, sales_value_raw
FROM     got_week_cnt
WHERE     week_cnt  = 1 + LENGTH ('&&Week_ID_CSV')
                - LENGTH (REPLACE ('&&Week_ID_CSV', ','))
;

Note that the got_week_cnt of the subquery is just your original query, with the added function of ACCOUNT.
You didn't post your tables or results, so I can't test it.
You didn't say which version you use, so I made a conservative assumption (Oracle 9 or later). In Oracle 11, there is an easier way to find the number of weeks.

Tags: Database

Similar Questions

  • Setting: display all values currently available - disabled

    Hello

    I want to show the value of parameter of an another table/folder.

    Such as:

    I created a spreadsheet of the EMP and DEPT/Table of records:

    SELECT E.Emp_Name, D.Dept_Name

    FROM Emp E, Dept. D

    WHERE E.Dept_ID = D.Dept_ID

    Question:

    1. How can I view Dept_ID (s) available in the EMP Table as an input parameter?
    2. If I can show Dept_Name to select between but Dept_ID and take as an input parameter?

    When I try to create the D.Dept_ID parameter 'Display all values currently available' option shows disabled and cannot be selected.

    Help, please.

    Thanks in advance.

    Manny

    I found the answer: How to insert the list of values (LOV) in Discoverer Desktop

    Thank you

  • How to hide lines if all values are zero (0) horizontally?

    Hello



    I have a requirement to hide lines according to the results if all values are zero horizontally.


    Example:
    
    
    Region   M1    M2   M3
    
    East     0      0    3
    
    West    10     20    0
    
    South   -5      0    5
    
    North    0      0    0
    In the example above only North line must be hidden from results because all measure values are zero.

    Can you get it someone please let me know the logic to do this?





    I thank in advance.

    Hello

    Why do not you try a simple as filter condition:

    M1! = 0 or m2! = 0 or m3! = 0

    Thank you
    Karthik M

  • Select only records where the column values are not all equal to zero

    Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
    with mytable as (
    select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all
    select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all
    select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all
    select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all
    
    select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual
    )
    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    order by itemtype
    I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.

    In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.

    Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?

    Thanks in advance!
    Mark

    Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
    {code}
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype

    less

    Select
    ItemType,
    Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
    de)
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype
    )
    where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
    apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
    )
    order of itemtype
    {code}

    Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...

    {code}
    WITH mainquery as (select all)
    Select * from mainquery
    less
    Select * from mainquery where (oct = 0, nov = 0, etc...)
    {code}

    Thanks again!
    Mark

    Published by: user455268 on March 1, 2012 19:13

    Published by: user455268 on March 1, 2012 19:16

    Hello

    You can do it with a HAVING clause:

    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    HAVING      MIN (theval)     != 0
    OR      MAX (theval)     != 0
    order by itemtype
    ;
    

    If the values are all 0, then the MIN and MAX will be 0.
    If the MIN or MAX is not 0, the values are all 0.

    This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
    If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique.

  • SQL Query to retrieve records for all after the Max Dates.

    Hello everyone,

    I am trying to retrieve the record more recent, based on the date field ( nextDate ).

    Currently, there are only 4 records in the MC_Maintenance table and two in the Machine table.

    Machine table

    MC_id             EquipID          

    1                      0227

    MC_id EquipID

    2                     0228

    ---------------------------------

    MC_Maintenance table

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010     

    2                      2                      07/01/2010

    3                      1                      2010-11-06

    4                      1                      07/11/2010

    I have am trying to accomplish is,.

    the list of the two machines of the table of the Machine with the MAX (Next_maint) control the list of MC_Maintenance results

    These are the records I want to display.

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010

    4                      1                      07/11/2010                 

    Here is the SQL query

    SELECT

           MC. MC_ID as ID,

    MC.complete_Date completed.

    MC.next_maint as nextDate,.

    MC.maint_notes as noted,.

    MC.facility Facility.

    M.EquipId,.

    $m.name as the name.

    M.SerialNumber SN.

    M.dept as dept.

    M.Freq as freq

    Of MC_Maintenance MC, Machine M

            where  MC. MC_ID = M.MC_ID

    '           Using MAX (nextDate)

    Any ideas would be useful.

    TJ

    I thought it was a simple group of problem?

    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID
    
  • SQL Query to retrieve records in a table with the same records or only one record in a table

    Hello

    Got a curious requirment to extract the Non-distincts records in a table

    Example of

    Account number Type of account
    12345SB
    12345

    SB

    12346CR
    12346SB
    12347SB
    12348CR
    12349SB

    Requrirement is to retrieve the records as follows

    Result must be

    Account number Type of account
    12345SB
    12345

    SB

    12347SB
    12348CR
    12349SB

    You will notice that 12346 which has two separate lines have been eliminated in the result. I tried several qeries to achieve this result, one or the other had a few mismatch. Can someone give me a request for it.

    Thanks in advance.

    SELECT ACCOUNT_NUMBER,

    ACCOUNT_TYPE

    DE)

    SELECT ACCOUNT_NUMBER,

    ACCOUNT_TYPE,

    COUNT (*) ON CNT_ACC (ACCOUNT_NUMBER PARTITION).

    COUNT (*) ON CNT_NUM_TYP (PARTITION ACCOUNT_NUMBER, ACCOUNT_TYPE)

    FROM T1)

    WHERE CNT_ACC = CNT_NUM_TYP;

    exit;

    12345 SB
    12345 SB
    12347 SB
    12348 CR
    12349 SB
  • Oracle 8i SQL - dealing with no record corresponding to a value

    WARNING: before you read this, please understand that I'm not an expert on SQL, so it is quite likely that I live something obvious upward...

    I'm doing a query a bit like the following:

    SELECT
    BOM.COMPONENT, BOM. QTY_PER, BOM. PARENT, BOM2. PARENT_QTY_PER
    Of
    BOM BOM, BOM BOM2
    WHERE
    BOM2.COMPONENT = BOM.PARENT AND
    BOM. TOP_ASSY = "ABC-123'.

    (Do not worry about my punctuation, my company only allows me to make [read-only] queries via Excel, I don't need semicolons)

    What I am doing is drawing on information provided by the Bill of materials (BOM) for a given assembly (BOM. TOP_ASSY). Each assembly has components (BOM.COMPONENT), and each element has a role of parent (BOM. PARENTS), it's in the. Each parent will also have its own party share of parent, unless the parent part corresponds to the assembly for which I ask (BOM. TOP_ASSY) - in the example above, the Assembly, I am looking for is ' ABC 123'.»

    This brings me to my problem. Given that I am looking for the QTY_PER for the component and the parent, I see two distinct copies of the Schedule table. And since the BOM. PARENT could match BOM. TOP_ASSY and BOM. TOP_ASSY has no parent, so it cannot be a component, then it would never be in the BOM.COMPONENT column. So, when I run this query, all the components that go directly into the top level Assembly ("ABC-123' ') are left off the coast of the query.

    Is it possible to retrieve the records for components that enter directly into the top-level Assembly and just doing BOM2. PARENT_QTY_PER equal to 0? Basically I want only BOM2. PARENT_QTY_PER to something equal if the parent is also a component and 0 if it is the top-level Assembly.

    Using NVL does not help, and given that I'm stuck with an Oracle 8i server question, I can't use CASE... WHEN two (well, I don't even know if it is possible with a case statement or not)...

    I don't even know if this is possible, but could someone let me know one way or the other?

    Thank you very much!

    Hello

    Sorry, these are typos. I wanted to say:

    SELECT
         c.COMPONENT,
         c.QTY_PER,
         c.PARENT,
         p.PARENT_QTY_PER
    FROM
         BOM     c,
         BOM     p
    WHERE
         p.COMPONENT (+)     = c.PARENT
    AND     c.TOP_ASSY       = 'ABC-123'
    

    Whenever you have a problem with the code, after the exact code you are running. Describing what you have can be useful, but describe it in addition to , not instead, it shows in fact.
    For example:

    user11033437 wrote:
    ... Since when I just added the

    p.COMPONENT (+)     = c.PARENT
    

    my request to indicate an outer join, it solves nothing.

    If you just add this line, it means that you are still using the alias BOM and BOM2? You now have two conditions, such as

    WHERE   p.COMPONENT      = c.PARENT
    AND     p.COMPONENT (+)     = c.PARENT
    

    I made typos: isn't possible that you could make some, too? No matter how attentive your description, you won't have to describe errors that you never knew you did.

  • Creating a popup message confirming the sending of form ONLY if all fields are correctly entered

    I use and learn Dreamweaver 2015.  I created a few forms to a Web site for a project, and while I got the correct validation for some fields (name required in the field name) settings, a valid email address for field email, etc, I can't find a way to bring up a window confirming the correct presentation if the fields have been correctly entered on the form.  If the fields are free of errors, I want to say something like "thanks for your message.  You should hear from us shortly. "I am limited to HTML5 and javascript.

    Thanks in advance!

  • In Firefox using the top menu, for example in Google images, videos, map, etc., of a web page are not activated with the mouse. This does not happen when you use Internet Explorer, because all links are available.

    A notification can up on some type of script, which then disappeared before I could take a note. After that links up on all web pages would not work by using the mouse cursor.
    It was only the links on a webpage, not on the menu bar or tabs above.

    To see if this happened on another browser, I opened the pages using Internet Explorer and open the links on all the pages that are controlled via the mouse. This sugested, it was a problem with Firefox.

    I uninstalled Firefox and installed a new application of the latest edition of Firefox, but the problem persists.

    No known cure for this problem.

    This problem may be caused by the Yahoo! toolbar as scopes as well down and covers the top of the browser window, allowing links in this part of the screen not clickable.

    You can keep an eye on this thread:

  • BB10 not all contacts are available in a scope Android app.

    Departure

    Application uses permission to contacts.

    What can be the problem?

    Thank you.

    Hello

    This was reported to one of the testers. Only 100 of its 700 + contacts was visible in the application. Problem solved by updating to the latest version of the OS.

  • Bought the whole package creative cloud. Everything works fine, all applications are available to install, except the one I was especially interested in what is Photoshop

    After using a trial version of photoshop some time ago he always says that I have to grant the product if I want to use. They push me to log into my account to see if I had a plan for photoshop and say that I don't have, while clearly..., however, I have no idea how to approach the issue, as all other apps seem to work?

    Hi Emil,

    To reset the hosts file using Adobe cleaning tool: -.

    https://helpx.Adobe.com/creative-cloud/KB/CC-cleaner-tool-installation-problems.html

  • Not all goods are available in my model

    It's my first site that I try to do my knowledge is limited, so I bought a template from themeforest called "lickowl."  It's all in the list of the assets (Muse) but all areas for 'Your Photo here'... who are all the pictures on the website are missing. I was given a current folder with all different sizes for the images, but they do not appear in the list of assets real muse. Is there a way I can create new capital that will link to their corresponding images that are already in the model? Can I just place the images in the template without going through the assets?

    Any help would be appreciated!

    Thank you

    CARI

    Hello

    You can simply place the images in your model from the current folder and the images will be automatically added in the active panel in Muse.

    Perhaps the creator of the desired model allows you to manually add all the pictures in the current folder, so that you don't have to go through the process of re - link assets again.

    Kind regards

    Rohit Nair

  • A 'Local disk (d)' suddenly appeared in my computer with? on a red disk. I can't get rid of it and in proprties all values are displayed as 0. Any ideas?

    My computer laptop xp pro, was 'shaking' a bit.

    Hello Bill,

    Glad to know that the issue was resolved. If you have other problems with Windows, please report it to Microsoft Community. We would be happy to help you.

  • I paid for Acrobat Reader DC, and not all applications are available to me,

    they say 'Add' when I go to tools to try to use one of the applications.  Then I tried to buy because I thought they wre invoiced separately, and he said that I had already.

    Then, Subscribe to the full version of Acrobat. You must install Acrobat and then use it instead of Acrobat Reader.

  • Only the formats that are available for export in first CC are .aaf and .xml?

    How to make a first draft of CC to a format compatible with the web look at one?

    Hi sheshehea,

    See that you select the calendar icon or the sequence in the project Panel before choosing File > export > Media

    Thank you

    Kevin

Maybe you are looking for