SQL Query help find albums from sale

Hi Experts,

I have the following data and the need to find the book Top sold in each type.

Book Type QTY

20Help the3
10Kitchen1
5Navigation2
30Help the4

Please let me how can know we get this simple SQL help?

Thank you

Bharat

Hello

Bharat Hegde wrote:

Hi all

I tried to use Dense_rank as below. But it gives me the top selling books. I need high library in each type...

This looks like a job for 'PARTITION BY type

For example:

WITH got_rnk AS

(

SELECT b.bid, b.type

SUM (o.quantity) AS total_quantity

DENSE_RANK () OVER ( PARTITION BY b.type

ORDER OF SUM (o.quantity) / / DESC

) AS rnk

B BOOK

o order1

WHERE b.bid = o.bid

GROUP BY b.bid, b.type

)

SELECT total_quantity, type submission

OF got_rnk

WHERE rnk = 1

;

. Aggregate functions (such as the SUM, above) are calculated before analytical functions, so an analytic function (such as DENSE_RANK above) may depend on an aggregate function; you don't need a separate subquery for that.

Tags: Database

Similar Questions

  • SQL query to find hiredate from emp where empno is max without subquery?

    What is the application?

    Hello

    select max(hiredate) keep (dense_rank last order by empno) from emp;
    

    Concerning
    Peter

  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

  • Help me with SQL Query to retrieve data from a view

    Hello Guru,

    I need help in my sql query.
    I use SQL TeraData.
    I want an Oracle result in the following form-

    Open tickets
    Open months failure / Repair Service s/o improvement request Total general
    2009-01-2 4 4 5 15
    2009-02 1 0 2 3 6
    2009-03 4 1 2 2 9
    Grand Total 7 5 8 10 30


    I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.

    Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
    COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
    FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
    WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
    AND (CASE
    WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
    WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
    WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
    END) = 1
    GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)

    After executing the query, I get the following error:
    3076: syntax Error: Data Type 'Time' does not match a defined Type name.
    :( Kindly help me with this and let me know where I'm wrong... Please.

    Messages indicates something wrong with your data... It would seem that the data does not match your format mask.

    Thus, the data or the format mask.

  • SQL query help

    Hello

    I have the table and professorid, studentid, classid.

    Please provide the sql code to find professor_id which hosts up to students.

    with t as)

    Select professor_id,

    ROW_NUMBER() over (order by count (distinct student_id) desc) rn

    from your_table

    Professor_id group

    )

    Select professor_id

    t

    where rn = 1

    /

    However, if there is a tie and a teacher number max of students has more meanings will select one of them. If you want that all teachers use:

    with t as)

    Select professor_id,

    DENSE_RANK() over (order by count (distinct student_id) desc) rn

    from your_table

    Professor_id group

    )

    Select professor_id

    t

    where rn = 1

    /

    SY.

  • SQl query to find out time between the different lines of transactions

    (See both images from an attachment to get the clear picture of the data and understand the question correctly.)

    I have a set of data like this in one of my paintings. (This is a simple representation of the original data.)

    Reference table1.jpg

    Id        | Type               | Value | Start_date | End_date

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

    ZTR0098 | ALLOW | 0 | 1 JUN | 2 JUN |

    ZTR0098 | ADTAX | 0 | 1 JUN | 2 JUN |

    ZTR0098 | MXTAX | 0 | 1 JUN | 9 JUN |

    ZTR0098 | ALLOW | 4. 3 JUN | 15 JUN |

    ZTR0098 | ADTAX | 44.00 | 3 JUN | 17-JUNE |

    ZTR0098 | MXTAX | 2. 10 JUN | 17-JUNE |

    ZTR0098 | ALLOW | 5. 16-JUNE | 20 JUN |

    ZTR0098 | ADTAX | 55,34 | 18 JUN | 22 JUN |

    ZTR0098 | MXTAX | 1. 18 JUN | 25 JUN |

    ZTR0098 | MXTAX | 6. 26 JUN | 31 AUG |

    ZTR0098 | ADTAX | 20.09. 23 JUN | 23 JUL |

    ZTR0098 | ALLOW | 8. 21 JUN | 31 AUG |

    ZTR0098 | ADTAX | 45. 24 JUL | 31 AUG |

    each line has a type and a rasthaus id to it. ID belongs to other parent tables. the value of each type is given, and the validity of each value is followed by a field start_date and end_date.

    All values start from 1 - JUN and expires on 31 - AUG. Now my requirement is to obtain a report that gives three columns for three different types (ALLOW, ADTAX and MXTAX) with combination of unique values in the effective time interval. Let me put the result below.

    Reference table2.jpg

    Id         | ALLOW | ADTAX | MXTAX |  Start_date | End_date

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

    ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |

    ZTR0098 | 4. 44.00 | 0 | 3 JUN | 9 JUN |

    ZTR0098 | 4. 44.00 | 2. 10 JUN | 15 JUN |

    ZTR0098 | 5. 44.00 | 2. 16-JUNE | 17-JUNE |

    ZTR0098 | 5. 55,34 | 1. 18 JUN | 20 JUN |

    ZTR0098 | 8. 55,34 | 1. 21 JUN | 22 JUN |

    ZTR0098 | 8. 20.09. 1. 23 JUN | 25 JUN |

    ZTR0098 | 8. 20.09. 6. 26 JUN | 23 JUL |

    ZTR0098 | 8. 45. 6. 23 JUL | 31 AUG |

    As you can see there are no duplicate rows for a combination of (ALLOW, ADTAX and MXTAX) with their respective dates in force. resulting in the above table. the first step is to convert lines to the column which is pretty obvious to do that by grouping on start_date and end_date colum, but the real deal is the time interval during which the combination of the values (ALLOW, ADTAX, and MXTAX) has remained constant.

    I wrote under query using Group by.

    Select

    ID,

    NVL (max (decode (type, "ALLOW", value)), 0) as ALLOW

    NVL (max (decode (type, 'ADTAX', value)), 0) as ADTAX

    NVL (max (decode (type, 'MXTAX', value)), 0) as MXTAX

    Start_date,

    End_date

    from my_table

    Group of start_date, end_date, id

    start_date, end_date

    the results it gives are like this:

    Reference table3.jpg

    Id       | ALLOW | ADTAX | MXTAX |  Start_date | End_date

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

    ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |

    ZTR0098 | 0 | 0 | 2. 1 JUN | 9 JUN |

    ZTR0098 | 4. 0 | 0 | 3 JUN | 15 JUN |

    ZTR0098 | 0 | 44.00 | 0 | 3 JUN | 17-JUNE |

    ZTR0098 | 0 | 0 | 2. 10 JUN | 17-JUNE |

    ZTR0098 | 5. 0 | 0 | 16-JUNE | 20 JUN |

    ZTR0098 | 0 | 55,34 | 0 | 18 JUN | 22 JUN |

    .   .

    . .

    like wise

    but I'm not able to determine the time intervals by using the SQL query.

    with

    Table1 as

    (select the id 'ZTR0098', 'ALLOW' type, 0 val, to_date('1-JUN','dd-MON') start_date, end_date Union to_date('2-JUN','dd-MON') double all the)

    Select 'ZTR0098', 'ADTAX', 0, to_date('1-JUN','dd-MON'), to_date('2-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'MXTAX', 0, to_date('1-JUN','dd-MON'), to_date('9-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'ALLOW', 4, to_date('3-JUN','dd-MON'), to_date('15-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'ADTAX', 44.00, to_date('3-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'MXTAX', 2, to_date('10-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'ALLOW', 5, to_date('16-JUN','dd-MON'), to_date('20-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'ADTAX', 55.34, to_date('18-JUN','dd-MON'), to_date('22-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'MXTAX', 1, to_date('18-JUN','dd-MON'), to_date('25-JUN','dd-MON') of all the double union

    Select 'ZTR0098', 'MXTAX', 6, to_date('26-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union

    Select 'ZTR0098', 'ADTAX', 20.09, to_date('23-JUN','dd-MON'), to_date('23-JUL','dd-MON') of all the double union

    Select 'ZTR0098', 'ALLOW', 8, to_date('21-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union

    Select 'ZTR0098', 'ADTAX', 45, to_date('24-JUL','dd-MON'), to_date('31-AUG','dd-MON') of the double

    ),

    days like

    (select level - 1 dte + to_date('1-JUN','dd-MON')

    of the double

    connect by level<= to_date('31-aug','dd-mon')="" -="" to_date('1-jun','dd-mon')="" +="">

    )

    Select id, allow, adtax, mxtax, min (dte) start_date, max (dte) end_date

    (select ID, dte, max (allow) allow, max (adtax) adtax, max (mxtax) mxtax,

    ROW_NUMBER() over (order by dte) row_number() - courses (partition by order max (allow), max (adtax), max (mxtax) by dte) gr

    go (select id, dte,

    -case when type = 'ALLOW' and dte between start_date and end_date then end val 0 otherwise allow.

    -case when type = "ADTAX" and dte between start_date and end_date then val 0 otherwise end adtax.

    -case when type = "MXTAX" and dte between start_date and end_date then val 0 otherwise end mxtax

    Table 1 t,

    days d

    where d.dte between t.start_date and t.end_date

    )

    Group by id, dte

    )

    Group by id, gr, allow, adtax, mxtax

    order by id, gr

    ID ALLOW ADTAX MXTAX START_DATE END_DATE
    ZTR0098 0 0 0 01/06/2015 02/06/2015
    ZTR0098 4 44 0 03/06/2015 09/06/2015
    ZTR0098 4 44 2 10/06/2015 15/06/2015
    ZTR0098 5 44 2 16/06/2015 17/06/2015
    ZTR0098 5 55,34 1 18/06/2015 20/06/2015
    ZTR0098 8 55,34 1 21/06/2015 22/06/2015
    ZTR0098 8 20.09 1 23/06/2015 25/06/2015
    ZTR0098 8 20.09 6 26/06/2015 23/07/2015
    ZTR0098 8 45 6 24/07/2015 31/08/2015

    Concerning

    Etbin

  • SQL query to find approved projects that are open

    Hello

    Can anyone provide a SQL query which will display only the approved projects that are open.

    Thank you

    Titas

    Try this

    Select project NAME of pa_projects_all
    where project_status_code = 'APPROVED '.
    and NVL (CLOSED_DATE, SYSDATE + 1) > SYSDATE

    Thank you
    Pradeep

  • SQL query to find out the version of discoverer

    Hello
    As a developer, is there a query sql DB the dorsal (or script) that can be run on DB to find out the version of Oracle Discoverer installed?
    The query will be different if the discoverer is used with the Oracle Applications (R12.1.3) compared to a Scout running on a plain stand alone Oracle database (Oracle applications not)?

    Thank you
    GG.

    Hello gg

    The VER_NAME and the VER_DESCRIPTION are usually never filled and can be ignnored.

    The VER_RELEASE is the NLY version as you rightly summised. This version is 100% compatible with the discoverer 11g and if you already have it you can go from 10g to 11g without changing anything in the EUL

    VER_MIN_CODE_VER is the minimum version of Oracle Discoverer which can be used with this EUL. In this case, 10.1.2.45.20 is 10g Release 2

    VER_EUL_TIMESTAMP is the date and time, this version of the EUL was published by Oracle - again you can ignore it

    Important fields are VER_RELEASE and VER_MIN_CODE_VER

    Hope this helps
    Best wishes
    Michael

  • SQL query - help with join

    Dear friends,

    Version of DB - 11.1.0.7... , I'm stuck with SQL basics today... need your help...

    The slot SQL tells me "cache them locks library" in the database that I will put up as a proactive measure.

    I'll be it works via shell script and include the table gv instance_name $ instance ... I'm a little confused as to how a 3rd table "gv$ instance ' can be introduced into the query in order to make the instance_name in the result set...

    SELECT * FROM)

    SELECT / * + LEADING (a) USE_HASH (u) * /.

    instance_name, INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.

    DECODE (sql_opcode, 1, 'CREATE TABLE', 2, 'INSERT') as "order."

    Event, mod(P1,16) p1, p2, p3

    COUNT (*) totalseconds

    , SUM (CASE WHEN wait_class = 'Application' THEN 1 ELSE 0 END) 'Application '.

    Of

    (SELECT

    a.*

    , TO_CHAR (CASE WHEN session_state = 'WAITING' THEN ELSE null END p1, '0XXXXXXXXXXXXXXX') p1hex

    , TO_CHAR (CASE WHEN session_state = "PENDING" THEN p2 ELSE null END, '0XXXXXXXXXXXXXXX') p2hex

    , TO_CHAR (CASE WHEN session_state = "PENDING" THEN ELSE null END p3, '0XXXXXXXXXXXXXXX') p3hex

    SGS $ active_session_history one) a

    u dba_users

    WHERE

    a.user_id = u.user_id

    AND sample_time BETWEEN sysdate-90 /(24*60) AND sysdate

    - AND a test of ('library cache lock', 'library cache pin")

    AND event like '% library '.

    GROUP BY

    INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.

    DECODE (sql_opcode, 1, 'CREATE TABLE', 'INSERT', 2),

    event, mod (p1, 16), p2, p3

    Having count (*) > 5

    ORDER BY

    TotalSeconds DESC

    , INST_ID select, blocking_session, username, session_id, sql_id, current_obj #, 'Order', event

    )

    WHERE

    ROWNUM < = 20

    /

    replace

    instance_name

    by

    (select instance_name gv$ instance where INST_ID select = a.inst_id) instance_name

    or select... in... a, u, gv$ instance where... and gv$ instance.inst_id (+) = a.inst_id...

  • Query to find when a sales order has been closed

    Hi all,

    Need to find the closing a sales order. Which means that the exact time. I know that the flags that must be taken into account. But what table/column contains the exact time that the order has been closed.

    Thank you

    If your workflow process details are not purged under query end_date will be firm order date.

    select a.instance_id
    , to_char(b.begin_date, 'DD-MON-RR HH24:MI:SS') begin_date
    ,to_char(b.end_date, 'DD-MON-RR HH24:MI:SS') end_date
    , a.process_name process
    from  wf_process_activities a, wf_item_activity_statuses b
    where b.item_type        = 'OEOH'
    and   b.item_key     in (select to_char(header_id) from oe_order_headers_all where order_number = )
    and a.process_name = 'CLOSE_HEADER_PROCESS'.
    and   b.process_activity = a.instance_id
    

    In R12 if you have not any customizations,
    Close current sets the wake-up time as the last day of the month, there is no component "hour".
    So order will be eligible from midnight on the last day of the month.
    First broadcast of program of what OEOH item type Workflow background process should be closing them.

    For example: If the waiting in the process activity of ' close - order "met first time on 09-may-2013(Any time in the month of May), wake up time will be the last day of the current month i.e. 31 May 2013 00:00.

  • SQL query problem finding difference in documents

    Hi all
    I use oracle 10g. I need emergency aid to find the difference in documents based on the date:

    I have sales of the table as below:

    seller SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012


    SALES_COUNT is up to man including the date of sale. Its similar cumulative number. John has total sales of 01/04/2012 to 03/04/2012 is 50 and same case for Denny. This SALES_COUNT will keep increasing with dates as sales continue to add in the table for each salesperson.
    But I want to have seprate for each seller counties.
    for example: JOHN SALES_COUNT 04/02/2012 is 30-20 = 10
    JOHN SALES_COUNT 03/04/2012 is 45-30 = 15
    DENNY SALES_COUNT, 02/04/2012 is 30-15 = 15
    JOHN SALES_COUNT 03/04/2012 is 50-30 = 20

    Please help me with this scenario and let me know if you need clarification. I would much appreciate your help.

    Thank you.

    This gives you what you want?

    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    )
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
          
    
  • SQL Query Help (not working not properly)

    Hello everyone,

    I use JDeveloper 12.1.2.0.0. I do a two-way communication using 3 tables, with links between them (and using schema HR).

    In my example, I have something like:

    Departments, employees, and the SalaryByJobs (I created this table where it shows a departmentd id, employee id, salary).

    Whenever I click on one OR more departments, the employees up-to-date table by putting on the table, employees who belong to the selected department and the salaryByjob to put the jobs of the employees selected on the employees table.

    So it's something like this:

    The departments selected-> employees selected-> salarybyjbobs of these employees.

    My query used (in the view) has the following code:

    SELECT Employees.COMMISSION_PCT,

    Employees.DEPARTMENT_ID,

    Employees.EMAIL,

    Employees.EMPLOYEE_ID,

    Employees.FIRST_NAME,

    Employees.HIRE_DATE,

    Employees.JOB_ID,

    Employees.LAST_NAME,

    Employees.MANAGER_ID,

    Employees.PHONE_NUMBER,

    Employees.SALARY

    Employees EMPLOYEES

    WHERE (department_id IN (select * from THE (select cast (in_list(:variavel3) as mytableType) double) a))

    Since I use the links, the employees table does not show anything at the beginning, so I added this to my query used to go: OR nvl(:variavel3,0) = 0

    But now, whenever I try to select multiple lines, it gives me the invalid numbers and I don't understand why...

    It's only one line of code and it is not in the bean.

    Can someone help me?

    PS - The bean will Department by Department, adds the departments with ',' and for each Department, gets employees who belongs to them.

    My best regards,

    Frederico Barracha.

    The expression NVL (: variavel3, 0) = 0 is not correct. The data type of the return value of the NVL function is considered to be equal to the data type of the argument of 1 (that is, the data type of the variable binding: variavel3). You said that this variable contained a list separated by commas to ID, so the data type of the variable is VARCHAR2. As long as you compare the NVL expression of a number, you get 'Invalid number' exception, because Oracle expects a numeric data type on the left side of the comparison operator.

    To avoid the exception "Invalid number", you can modify the expression by using one of the following options:

    : variavel3 IS NULL

    NVL (: variavel3, ' *') = ' *'

    NVL (: variavel3, ' 0') = '0'

    Option 1, so the simplest and clearest.

    Dimitar

  • SQL query to find the value of a column as well!

    Hi all

    I have to write a query that needs to retrieve the value of a column in table B if the column value is Null in the Table A. Please find below the sample table.

    Table A:
    *******
    EmpNumber ID
    ------------------------------
    1 12345
    2
    3 14789
    4
    5 74563

    Table B:
    *******
    EmpNumber ID
    -----------------------------
    1 12345
    2 78451
    3 14789
    4 12212
    5 74563

    In the table a second and third rows have value for EmpNumber. The query should look for table B for EmpNumber value. Please advise me to make this request.

    Thank you

    This?

    select      a.id,
         nvl(a.empnumber,b.empnumber) empnumber
    from tabA a, tabB b
    where a.id = b.id;
    
  • SQL statement Help Find County

    I have an Oracle table with lot of columns and I want to check if 3 of my columns contain all values (I don't like the real value, there, I just want to know how many of them have a value). Allows so say for example:

    Table columns: ID, A, B, C

    These conditions would be true... value exists in both A AND B, A AND C or B AND C columns. If a value exists in A and not B or C, then it should not be counted. Similarly, if a value exists in B and not A or C, or there is a value C and not A or B, then he shouldn't have counted.

    ----------------------
    | ID | A | B | C |
    ----------------------
    | 1. X | X | | <-true
    | 1. X | X | X | <-true
    | 1. X | | X | <-true
    | 1 | | X | X | <-true
    | 1. X | | | <-false
    | 1 | | X | | <-false
    | 1 | | | X | <-false
    | 1 | | | | <-false
    | 2. X | X | | <-true
    | 2. X | X | X | <-true
    | 2. X | | X | <-true
    | 2 | | X | X | <-true
    | 2. X | | | <-false
    | 2 | | X | | <-false
    | 2 | | | X | <-false
    | 2 | | | | <-false
    ----------------------

    Static values will be my ID. I want to check against 2 ID who I know will always be the case. I tried to write, but I'm sure I'm doing something wrong because my count was very high (about 1.7 million records over 2 million).

    That's what I wrote:

    Select count (*)
    FROM table1
    where (ID = "1" or ID = "2")
    (A is not null and B is not null)
    or (A is not null and is not null)
    or (B is not null and is not null);

    Thanks for your help!

    Published by: 973560 on March 14, 2013 12:03

    Hello

    One way to see how many rows have values in at least 2 of the following columns:

    SELECT  COUNT (*)     AS cnt
    FROM     table1
    WHERE     id     IN ('1', '2')     -- is id really a string?
    AND     NVL2 (a, 1, 0)
          + NVL2 (b, 1, 0)
          + NVL2 (c, 1, 0) >= 2
    ;
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in the palces.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • The join SQL query help

    I'm just having a bit of troubel get a correct join query - I thought it was an Inner Join, but I don't get the results I expect.

    My table structure is:

    Table: lodges

    LodgeID (PK)

    Lodge

    etc.

    Table: implemented application

    NominationID (PK)

    Category

    LodgeID

    Year

    So I try to use this structure to replicate this page:

    http://www.safariawards.com/nominees12/

    That is to say a list of boxes for each category, they are appointed on.

    The query I've tried looks like this:

    SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. NominationID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge

    But this product:

    http://www.safariawards.com/nominees12/southernafrica.php

    Its the right number of results, but not the list on the right of the boxes - for example British Airwways is not LodgeID 786

    If anyone could help with the SQL right for what would be well appreciated.

    That you join on the wrong column. Try this:

    SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. LodgeID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge

Maybe you are looking for

  • try to set up synchronization, a lot of problems.

    I just had to reset FF by default, and he forgot my synced data. No problem, I'll just be reintroduced in this one. Of course, I went to tools-> Options-> synchronization. Then things are weird. So I tried 'Set up Firefox sync', it opens another wind

  • How can I synchronize Safari bookmarks with those in Firefox?

    I have a PC running Firefix and Firefox Sync OK. I have an ipad 2 with Firefox Home installed and connected fine to my FF sync account. I was expecting FF home to synchronize bookmarks on ipad Safari with those on the desktop. Apparently not so much.

  • Energy consumption high (30W) on Tecra A4

    Hello! My A4 battery only lasts for about AN hour at full load! NotebookHardwareControl shows a 30W energy consumption. What's wrong? Círdanp.s. I recently bought this used laptop.

  • new security issues

    identifying Apple arises my two security questions - I forgot the awnsers - I'll get email to reset the security questions - problem is: I have never this email - could be an old email address - what can I do

  • Analysis without the printer cartridges

    How can I scan an image to a .pdf file if the color cartridge is empty. Cannot get replacement cartridge message. I need to print only the scan to a file.