Php sql query

hello
i need to write a query that displays the total sum of the 10 highest values from 15 values in a query.
i.e, i want to select the ten highest values from say 10,10,10,8,7,6,6,6,5,4,3,3,3,2,2
to give me 10,10,10,8,7,6,6,6,5,4 which would then give me a value 72
is there an sql command that would do this?
at the moment, i'm having to do it like thus:
function drawleaguetable()
$pointscore = array();
$sql = "select Name, Points  from Points_Table where Name='Budgie'  order by Points desc, Name asc ";
$result = mysql_query($sql);
print("<table id='leaguedatatab'  border='0' >");
print("<tr><th colspan='2'><h2>League Table</h2></th></tr>");
while ($db_field = mysql_fetch_assoc($result))
   array_push($pointscore, $db_field['Points']);
   print("<tr><td>".$db_field['Name']."</td><td>".$db_field['Points']." pts <br /> </td></tr>");
echo("Top Ten Scores:");
for($i=0; $i<10; $i++)
echo($pointscore[$i].",");
$eosscore = $eosscore+$pointscore[$i];
echo("<br/>Best Of Ten Score: ".$eosscore);
print ("</table><br />");
this sort of does the job for me, but what i want is to display the total sum of all 15 vaules and then also display the total of the top 10 values. i know i would need to use sum(Points) as TotalPoints to do this, but i just can't get that to work in conjunctive with  the sum for the top 10 values......if that makes sense.
sorry, forgot the link. http://www.southmoorac.com/bestten.php
i'm also just picking up one name at the moment. want to get that right first.
Please help, it's near the end of my fishing clubs season, and i need to get this sorted for the web page!!

Is there any way you could write the totals to the DB first, or is it too late for that?  If you had a column that stored a running total it would make it a lot easier to do what you need to do.

Similar Messages

  • Php code about sql query

    for example:
    create table testtable (
    order_number number(4),
    item_id number(4),
    quantity number(8),
    item_desc varchar2(16)
    insert into testtable values (1001,1,10,'apple');
    insert into testtable values (1001,2,20,'banana');
    insert into testtable values (1002,2,50,'banana');
    insert into testtable values (1002,1,30,'apple');
    insert into testtable values (1003,3,60,'orange');
    insert into testtable values (1004,3,50,'orange');
    commit;
    Table Test DATA
    order_number item_id quantity item_desc
    1001 1 10 apple
    1001 2 20 banana
    1002 2 50 banana
    1002 1 30 apple
    1003 3 60 orange
    1004 3 50 orange
    i want to make above sql query output in 3 pages.
    order_number item_id quantity item_desc
    1001 1 10 apple
    1001 2 20 banana
    when i click next_page it output below:
    order_number item_id quantity item_desc
    1002 2 50 banana
    1002 1 30 apple
    and when i click next_page again it will output below:
    order_number item_id quantity item_desc
    1003 3 60 orange
    1004 3 50 orange
    using url:http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_paged.html
    please look at three php code below:
    php code:
    <?php
    $con = oci_connect('apps','apps','prod');
    $sql = "select distinct h.order_number,h.order_type_id,h.price_list_id
    from oe_order_headers_all h
    where to_char(h.ordered_date,'YYYYMMDD') = '20060627'
    and h.org_id = 82
    order by order_number ASC";
    $result = oci_parse($con,$sql);
    oci_execute($result);
    echo "<table border = 1>";
    echo "<tr><td>order_number</td>";
    echo "<td>order_type</td>";
    echo "<td>price_id</td></tr>";
    while ($rows = oci_fetch_array($result,BOTH_NUM)) {
    echo "<tr><td>". $rows[0]."</td>";
    echo "<td>".$rows[1]."</td>";
    echo "<td>".$rows[2]."</td></tr>";
    ?>
    pager_functions.php
    <?php
    function total_pages($total_rows, $rows_per_page) {
    if ( $total_rows < 1 ) $total_rows = 1;
    return ceil($total_rows/$rows_per_page);
    function page_to_row($current_page, $rows_per_page) {
    $start_row = ($current_page-1) * $rows_per_page + 1;
    return $start_row;
    function count_rows(& $conn, $select) {
    $sql = "SELECT COUNT(*) AS num_rows FROM($select)";
    $stmt = oci_parse($conn,$sql);
    oci_define_by_name($stmt,"NUM_ROWS",$num_rows);
    oci_execute($stmt);
    oci_fetch($stmt);
    return $num_rows;
    function & paged_result(& $conn, $select, $start_row, $rows_per_page) {
    $sql = "SELECT
    FROM
    SELECT
    r.*, ROWNUM as row_number
    FROM
    ( $select ) r
    WHERE
    ROWNUM <= :end_row
    WHERE :start_row <= row_number";
    $stmt = oci_parse($conn,$sql);
    oci_bind_by_name($stmt, ':start_row', $start_row);
    // Calculate the number of the last row in the page
    $end_row = $start_row + $rows_per_page - 1;
    oci_bind_by_name($stmt, ':end_row', $end_row);
    oci_execute($stmt);
    // Prefetch the number of rows per page
    oci_set_prefetch($stmt, $rows_per_page);
    return $stmt;
    ?>
    outpages.php:
    <?php
    $conn = OCILogon('scott', 'tiger') or die ("Unable to connect to db");
    require_once 'pager_functions.php';
    $rows_per_page = 3;
    $url = 'results.php'; // URL to this script
    $sql = 'SELECT * FROM testtable ORDER BY rank ASC'; // The unfiltered
    // Get the total page count from the number of rows
    $total_rows = count_rows($conn,$sql);
    $total_pages = total_pages($total_rows, $rows_per_page);
    // Make sure the page number is a sane value
    if ( !isset($_GET['page']) ||
    !preg_match('/^[0-9]+$/',$_GET['page']) ||
    $_GET['page'] < 1 ) {
    $_GET['page'] = 1;
    } else if ( $_GET['page'] > $total_pages ) {
    $_GET['page'] = $total_pages;
    // Translate the page number into a starting row number
    $start_row = page_to_row($_GET['page'], $rows_per_page);
    // Filter to a single page of rows
    $stmt = & paged_result($conn, $sql, $start_row, $rows_per_page);
    ?>
    <table width="600">
    <caption>Feedster Top 500 Blogs [#<?php echo $_GET['page']; ?>]</caption>
    <thead>
    <tr>
    <th>Rank</th>
    <th>Blog</th>
    <th>Inbound Links</th>
    </tr>
    </thead>
    <tbody>
    <?php while (OCIFetchinto($stmt,$row,OCI_ASSOC)) { ?>
    <tr valign="top">
    <td align="right"><?php echo htmlspecialchars($row['RANK']); ?></td>
    <td>
    ">
    <?php echo htmlspecialchars($row['NAME']); ?>
    </a>
    </td>
    <td align="right"><?php echo htmlspecialchars($row['LINKS']); ?></td>
    </tr>
    <?php } ?>
    </tbody>
    <tfoot>
    <tr>
    <td colspan="3" align="center">
    <?php echo draw_pager($url, $total_pages, $_GET['page']); ?>
    </td>
    </tr>
    </tfoot>
    </table>
    ?>
    above two php codes in the same folder
    when i run outpages.php it runs below result:
    Feedster Top 500 Blogs [#1]
    Rank Blog InboundLinks
    may be above php code doesn't output what i mean .
    who can help me ?

    Hi,
    Your table testtable is defined as follows:
    create table testtable (
    order_number number(4),
    item_id number(4),
    quantity number(8),
    item_desc varchar2(16)
    In your script, you are refering to the columns 'RANK', 'NAME', 'URL' and 'LINKS'!!!
    They simly doesn't exist.
    You simply copied and pasted a snippet from the oracle-php-cookbook without adapting it to your needs. (And I assume without understanding, what that code will do.)
    Greetings from Hamburg
    Thorsten Körner

  • Issue in creation of group in oim database through sql query.

    hi guys,
    i am trying to create a group in oim database through sql query:
    insert into ugp(ugp_key,ugp_name,ugp_create,ugp_update,ugp_createby,ugp_updateby,)values(786,'dbrole','09-jul-12','09-jul-12',1,1);
    it is inserting the group in ugp table but it is not showing in admin console.
    After that i also tried with this query:
    insert into gpp(ugp_key,gpp_ugp_key,gpp_write,gpp_delete,gpp_create,gpp_createby,gpp_update,gpp_updateby)values(786,1,1,1,'09-jul-12',1,'09-jul-12',1);
    After that i tried with this query.but still no use.
    and i also tried to assign a user to the group through query:
    insert into usg(ugp_key,usr_key,usg_priority,usg_create,usg_update,usg_createby,usg_updateby)values(4,81,1,'09-jul-12','09-jul-12',1,1);
    But still the same problem.it is inserting in db.but not listing in admin console.
    thanks,
    hanuman.

    Hanuman Thota wrote:
    hi vladimir,
    i didn't find this 'ugp_seq'.is this a table or column?where is it?
    It is a sequence.
    See here for details on oracle sequences:
    http://www.techonthenet.com/oracle/sequences.php
    Most of the OIM database schema is created with the following script, located in the RCU distribution:
    $RCU_HOME/rcu/integration/oim/sql/xell.sql
    there you'll find plenty of sequence creation directives like:
    create sequence UGP_SEQ
    increment by 1
    start with 1
    cache 20
    to create a sequence, and
    INSERT INTO UGP (UGP_KEY, UGP_NAME, UGP_UPDATEBY, UGP_UPDATE, UGP_CREATEBY, UGP_CREATE,UGP_ROWVER, UGP_DATA_LEVEL, UGP_ROLE_CATEGORY_KEY, UGP_ROLE_OWNER_KEY, UGP_DISPLAY_NAME, UGP_ROLENAME, UGP_DESCRIPTION, UGP_NAMESPACE)
    VALUES (ugp_seq.nextval,'SYSTEM ADMINISTRATORS', sysadmUsrKey , SYSDATE,sysadmUsrKey , SYSDATE, hextoraw('0000000000000000'), 1, roleCategoryKey, sysadmUsrKey, 'SYSTEM ADMINISTRATORS', 'SYSTEM ADMINISTRATORS', 'System Administrator role for OIM', 'Default');
    as a sequence usage example.
    Regards,
    Vladimir

  • SQL Query returns values like "---" and "NA"

    Hi
              When I execute a sql query in MII it returns values like "---" and "NA" for empty Char and numeric fields respectively.
    I have checked the database and made sure that these fields does not have any value. This happens only when I run the query through MII. Can any one know how can we get rid of these values?
    Thanks in advance
    Shaji

    Shaji,
    MII sets those values as a default if it discovers null values in a query result. You can change this default behaviour in several ways.
    First, have a look at the document [Setting custom null values in XML|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70628af0-8ec4-2c10-7da2-f451e412dd8f?quicklink=index&overridelayout=true]. Then you may also use SQL functions like [NVL|http://www.techonthenet.com/oracle/functions/nvl.php] to change the value directly in the SQL query. You can also change the value inside the MII BLT to whatever you need.
    Michael

  • How to write sql query with many parameter in ireport

    hai,
    i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
    but i don't know to create query if more than 1 parameter.i also have parameter such as
    $P{entity},$P{id},$P{ic}.please help me for this.
    thanks

    You are in the wrong place. The ireport support forum may be found here
    http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9

  • SQL Query to get statistics report

    Hi Experts,
    I need to get a report for CPU utilization,Memory Usage,Event Waits, Connection Spool and Shared Spool for a given query.
    Need some tips from you to get that report.
    Thanks,

    Its not something to trace my slow running sql query.
    I need to provide a report regarding Database Statistics on a specific process from front end PHP.
    Previously, i have provided you the different environment Oracle Version, here is the exact version in which i need to generate the report.
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production   
    PL/SQL Release 11.1.0.7.0 - Production                                         
    CORE     11.1.0.7.0     Production                                                     
    TNS for Solaris: Version 11.1.0.7.0 - Production                               
    NLSRTL Version 11.1.0.7.0 - Production                                          This Database server is controlled by Client and having just limited access (not able to access the Trace Files).
    Can someone tell me to generate the requested report using some v$ Views.
    Thanks,
    Edited by: DharanV on Apr 15, 2010 8:01 PM
    added some more details to make it much clear

  • SQL Query To Select The 5th Element

    In the report I am currently working on, I am using an Add Command custom SQL query to pull the data that I need. The structure is a Call and a list of associated Activities. In this particular scenario, there are 8 activity notes for a type of call and I want to return the 5th one. The activity notes are a specific sequence of captured actions and I need the note from the 5th step in the sequence.
    This is what I have come up with:
    SELECT CALL.call_id,
         (select top 1 from (select top 5 CONVERT(char(8000),ACTIVITY.activity_note) from ACTIVITY
          where CALL.call_id = ACTIVITY.call_id
          order by ACTIVITY.creat_date desc))
         as activity_tx
    FROM CALL
    The intent of the Top 5 was to get the first 5 activity notes, of which the 5th note would be the last, then reverse sort them so I could take the Top 1 (which would be the 5th of 8). But I am getting a vague syntax error between "from" and "order by". Any suggestions would be appreciated.
    Thanks!
    Fuskie
    Who thought he had a solution but is flummoxed he can't bring it home...

    Hello,
    Let me explain that Crystal assumes the user knows how to write SQL. We only report on the data provided by the SQL you write.
    I did a quick search using Microsofts new search engine - www.bing.com and it returned this as well as lots more:
    http://forums.devshed.com/php-development-5/how-to-access-a-certain-element-in-the-results-of-606217.html
    Try searching in MSSQL's site also for more info on how to get the results you are looking for.
    Thank you
    Don

  • Can't  write right sql query by two tables

    Hello
    Everyone,
    I am trying to get a sql query by two tables,
    table:container
    <pre class="jive-pre">
    from_dest_id     number
    ship_from_desc     varchar
    to_dest_id     number
    </pre>
    table: label_fromat (changeless)
    <pre class="jive-pre">
    SORT_ORDER     number
    PREFIX     varchar2
    VARIABLE_NAME varchar2
    SUFFIX varchar2
    LF_COMMENT varchar2
    </pre>
    the sql which i need is
    a. table CONTAINER 's each column should have LABLE_FORMAT 's PREFIX before and SUFFIX back ,and these columns is connected
    example : the query output should be like this :
    <pre class="jive-pre">
    PREFIX||from_dest_id||SUFFIX ||PREFIX||ship_from_desc||SUFFIX ||PREFIX|| to_dest_id||SUFFIX
    </pre>
    every PREFIX and SUFFIX are come from LABEL_FORMAT's column VARIABLE_NAME (they are different)
    column SORT_ORDER decide the sequence, for the example above: Column from_dest_id order is 1, ship_from_desc is 2,to_dest_id is 3
    b. table LABEL_FORMAT's column VARIABLE_NAME have values ('from_dest_id','ship_from_desc','to_dest_id')
    If table CONTAINER only have one record i can do it myself,
    But actually it is more than one record,I do not know how to do
    May be this should be used PL/SQL,or a Function ,Cursor ,Procedure
    I am not good at these
    Any tips will be very helpful for me
    Thanks
    Saven

    Hi, Saven,
    Presenting data from multiple rows as a single string is called String Aggregation . This page:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    shows many ways to do it, suited to different requirements, and different versions of Oracle.
    In Oracle 10 (and up) you can do this:
    SELECT     REPLACE ( SYS_CONNECT_BY_PATH ( f.prefix || ' '
                                   || CASE  f.variable_name
                                        WHEN 'FROM_DEST_ID'
                                       THEN  from_dest_id
                                       WHEN 'SHIP_FROM_DESC'
                                       THEN  ship_from_desc
                                       WHEN 'TO_DEST_ID'
                                       THEN  to_dest_id
                                      END
                                   || ' '
                                   || f.suffix
                               , '~?'
              , '~?'
              )     AS output_txt
    FROM          container     c
    CROSS JOIN     label_format     f
    WHERE          CONNECT_BY_ISLEAF     = 1
    START WITH     f.sort_order     = 1
    CONNECT BY     f.sort_order     = PRIOR f.sort_order + 1
         AND     c.from_dest_id     = PRIOR c.from_dest_id
    saven wrote:If table CONTAINER only have one record i can do it myself,
    But actually it is more than one record,I do not know how to do In that case, why did you post an example that only has one row in container?
    The query above assumes
    something in container (I used from_dest_id in the example above) is unique,
    you don't mind having a space after prefix and before from_dest_id,
    you want one row of output for every row in container, and
    you can identify some string ('~?' in the example above) that never occurs in the concatenated data.

  • Sql query using EJB

    I'm trying to adapt my sql query i use for php in order to return zipcodes using a radial search.
    This is my query that i use in php:
    $strSql2 = "SELECT * FROM Zips where (DEGREES(ACOS(SIN(RADIANS(" . $this->lat . ")) * SIN(RADIANS(lat)) + COS(RADIANS(" . $this->lat . ")) * COS(RADIANS(lat)) * COS(RADIANS(" . $this->lon . " - lon)))) * 69.090909) <= " . $distance;I need to adapt this to work for my finder method in my jaws.xml file, here is what i have so far, i know it doesn't work, especially with the < sign in there ;)
             <finder>
               <name>findByDistance</name>
               <query>(DEGREES(ACOS(SIN(RADIANS(" . $this->lat . ")) * SIN(RADIANS(lat)) + COS(RADIANS(" . $this->lat . ")) * COS(RADIANS(lat)) * COS(RADIANS(" . $this->lon . " -lon)))) * 69.090909) <= " . $distance</query>
               <order>zipcode ASC</order>
             </finder>          Thanks for your help guys.

    Hello,
    If the ">" or "<" are creating the problem then u can use the following approach. Here i am explaing it with an example:
    EJB QL statements are declared in XML deployment descriptors. XML uses the greater than (�>�) and less than (�<�) characters as delimiters for tags, so using these symbols in the EJB QL statements will cause parsing errors unless CDATA sections are used. For example, the following EJB QL statement causes a parsing error, because the XML parser cannot distinguish the use of the �>� symbol from a delimiter to a XML tag:
    <query>
    <query-method>
    <method-name>findWithPaymentGreaterThan</method-name>
    <method-params>java.lang.Double</method-params>
    </query-method>
    <ejb-ql>
    SELECT OBJECT( r ) FROM Reservation r
    WHERE r.amountPaid > ?1
    </ejb-ql>
    </query>
    To avoid this problem, the EJB QL statement should be placed in a CDATA section:
    <query>
    <query-method>
    <method-name>findWithPaymentGreaterThan</method-name>
    <method-params>java.lang.Double</method-params>
    </query-method>
    <ejb-ql>
    <![CDATA[
    SELECT OBJECT( r ) FROM Reservation r
    WHERE r.amountPaid > 300.00
    ]]>
    </ejb-ql>
    </query>
    The CDATA section takes the form <![CDATA[ literal-text ]]>. When an XML processor encounters a CDATA section it doesn�t attempt to parse the contents enclosed by the CDATA section, instead the parser treats it as literal text .

  • Need sql query to import from excel sheet

    Hey , i need sql query to import from excel sheet.
    i work in a company where i need to daily update the data from excel sheet.
    if i get a shortcut method i ill be very thank full to you guys to reduce my work upto 10 %.

    any query which can inert from excel file?
    Sort of. Certainly not anything as simple as what you seem to hope for. Check out this very good PHP class:
    PHPExcel - Home

  • Need help writing sql query

    i am trying to write sql query for a single recordset.
    I have an items table with all the standard item info and an item_colorID.
    i have a color_lookup table with 2 columns, item_colorID and color_ID
    i have a colors table with 2 columns, color_ID and color
    i want to join the tables and filter it so that a repeat region shows dynamic data of item name, description, thumb, price
    and also a list/menu dynamically populated by color
    filtered so that each item shows in the list/menu only the colors that the item has available.
    i have tried different variations of this sql
    SELECT * FROM items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
    but the list/menu shows every color choice multiplied by the number of items in that color
    ie  White will show 80+ times.
    thanks for your help,
    jim balthrop

    bregent,
    thanks for your help.
    I am building a shopping cart and i have a recordset to list the items and a repeat region for that recordset
    i have a second recordset for the colors joined to the item_colorID nested inside the repeat region.
    the shopping cart software has a 'lookup from recordset' choice for the add to cart servior behavior
    and then i bind to the columns on the cart page.
    it produces this code
    if (isset($totalRows_rs_itemscat3) && $totalRows_rs_itemscat3 > 0)    {
        $row_rs_itemscat3 = WAEC_findRecordMySQL($rs_itemscat3, "item_ID", $ATC_itemID);
        if ($row_rs_itemscat3)    {
          $ATC_itemName = "".$row_rs_itemscat3['itemName']  ."";// column binding
          $ATC_itemDescription = "".$row_rs_itemscat3['itemShortDesc']  ."";// column binding
          $ATC_itemWeight = floatval("".$row_rs_itemscat3['itemWeight']  ."");// column binding
          $ATC_itemQuantity = "".$_POST["Farrington_1_Quantity_Add"]  ."";// column binding
          $ATC_itemPrice = floatval("".$row_rs_itemscat3['itemPrice']  ."");// column binding
          $ATC_itemThumbnail = "".$row_rs_itemscat3['itemThumb']  ."";// column binding
          $ATC_itemcolorchoice = "".$row_rs_colors['color']  ."";// column binding
          mysql_data_seek($rs_itemscat3, 0);
          $row_rs_itemscat3 = mysql_fetch_assoc($rs_itemscat3);
    the column binding for the colors is from a different recordset and when redirecting to the cart page the color info will not show.
    So my thinking is if i could get the color list/menu to populate from the same recordset as the item listing, it would solve my add to cart server behavior.
    Is it possible to do this with only one recordset?
    the products page and the cart page can be seen
    http://www.farrington-enterprises.com/rain-gutters.php
    add an item to the cart with any color choice and the color info does not carry to the cart.

  • Hosting company does not support SQL query with OUTFILE clause

    From my mysql database, I want to allow the user to run a query and produce a csv / text file of our membership database.   Unfortunately,  I just found out my hosting company does not support the SQL query with OUTFILE clause for MySQL database.
    Are there any other options available to produce a file besides me running the query in phpadmin and making the file available to users.
    Thanks.  George

    Maybe this external Export Mysql data to CSV - PHP tutorial will be of help
    Cheers,
    Günter

  • Returning 25th to 40th result of SQL query, do I use a cursor?

    I have a complex SQL query that returns ALL the results I am looking for. I would to be able to only return the Nth to Nth result, like just the 50th to 70th record counts (assuming there is a sort by in the statement so it always returns in the same order.)
    I thought of using a cursor and checking %ROWCOUNT and only returning the proper rows, but that seemed like it would be inefficient. I could do the same on my front end (PHP 4.0.6) relatively easily, but that would be a really inefficient way to retrieve 20 records from a query with 1000+ records returned.

    Thanks, the links were helpful.
    Since rowcount ignores my order by clause, I have attempted to find ways to overcome this. I have tried using the rowcount method by recreating my tables as index-orginized with an index on the column that I need to be ordered by. As a result of this, I have come accross two problems.
    1. then index does not seem to update the order when I update the column. The column being indexed is a date type. The values added are usually sysdate, so although new elements are added properly, updating old ones does not change their index position.
    2. I really need to access the items from most recent to oldest, thus desc. Since I am returning by rowcount, this makes it difficult. The following SQL is the best I can come up with and requires the output to be looped in reverse for display in the correct order:
    select postid, subject, to_char(lastmod, 'Month FMDD, YYYY HH')||':'||to_char(lastmod, 'MIam'), name from (select t.postid, t.subject, t.lastmod, r.name, rownum ro from forumtopic t, forumrooms r where t.roomid = '1000668' and t.roomid = r.roomid and r.useraccess = '1') where ro between ((select count(*) from forumtopic subt where subt.roomid = '1000668')-40) and ((select count(*) from forumtopic subt where subt.roomid = '1000668')-25);

  • SQL query - combining AND and OR

    I am just tweaking a page here:
    http://www.goodsafariguide.net/africanhorseback/index102.php
    Basically just changing the nominations history part to just show nominations from 2013 and 2011, as some of the palces had too long a list of nominations.
    So the original SQL query was:
    SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE LodgeID = 288 ORDER BY Year DESC, CATEGORY ASC
    So I want it to now display nominations for that LodgeID, but just for 2011 and 2013, which I thought should just be:
    SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE LodgeID = 288 AND (Year='2013' OR '2011') ORDER BY Year DESC, CATEGORY ASC
    But that isn't working. I've tried a few variations, with and without the inverted commas, but can't seem to get it.
    Any suggestions?

    Try this:
    SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE (Year='2013' OR Year='2011') AND LodgeID = '288' ORDER BY Year DESC, CATEGORY ASC
    if you wanted a run of years like 2011 , 2012 and 2013 you could use:
    SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE Year BETWEEN '2011' AND '2013' AND LodgeID = '288' ORDER BY Year DESC, CATEGORY ASC

  • SQL Query to BI Publisher Report

    I'm new to BI Publisher. My results from my SQL query did not load properly into BI Publisher. Below is the XML. Can someone help? Thanks!
    <?xml version="1.0" ?>
    - <RESULTSET>
    - <ROWSET id="0">
    - <ROW id="1">
    - <COLUMN NAME="ID">
    - <![CDATA[
    12345
      ]]>
    </COLUMN>
    - <COLUMN NAME="NAME">
    - <![CDATA[
    Mary Jones
      ]]>
    </COLUMN>
    <COLUMN NAME="Gender">F</COLUMN>
    <COLUMN NAME="Address">10-10 203rd Street</COLUMN>
    <COLUMN NAME="City">New York</COLUMN>
    <COLUMN NAME="State">NY</COLUMN>
    <COLUMN NAME="Zip">10013</COLUMN>
    - <COLUMN NAME="Notes">
    - <![CDATA[
    Pending application submission.
      ]]>
    </COLUMN>
    <COLUMN NAME="Birth Date">8/1/1975</COLUMN>
    </ROW>
    </ROWSET>
    </RESULTSET>

    Hi Sonal,
    a possible solution for this can be the use of a lead function (take a look once here where the function is explained http://www.oracle-base.com/articles/misc/LagLeadAnalyticFunctions.php)
    Hope this can help you out.
    Kr
    A

Maybe you are looking for