Need help for SQL Query
Hi Friends,
I am using below query to genearet one report.
{code}
distinct a.plan_id,
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = a.plan_id)
"EXT_PAN_REF",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = b.depends_on_ba_plan_id)
"EXT_PAN_REF1",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = c.drp_plan_id)
"EXT_PAN_REF2",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = d.srp_plan_id)
"EXT_PAN_REF3",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = e.DRP_TO_DRP_PLAN_ID)
"EXT_PAN_REF4",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = f.srp_plan_id)
"EXT_PAN_REF5"
FROM BK9_T_BUSINESS_ACTIVITY a,
BK9_T_BA_DEPENDENCY b,
BK9_T_BA_DRP_DEP c,
BK9_T_BA_SRP_DEP d,
BK9_T_DRP_DEPENDENCY e,
BK9_T_SYSTEM_DEPENDENCY f
WHERE a.plan_id = b.ba_to_ba_plan_id
AND a.plan_id = c.ba_plan_id
AND a.plan_id = d.ba_plan_id
AND c.drp_plan_id = e.DRP_TO_DRP_PLAN_ID
AND e.DRP_TO_DRP_PLAN_ID = f.drp_plan_id
{code}
My output is like this :
{code}
22767 19093 19095 19049 19049 19059
22767 19093 19095 19049 19049 19060
22767 19093 19095 19062 19062 19060
22767 19093 19095 19062 19062 19061
22768 19094 19093 19062 19062 19060
22768 19094 19093 19062 19062 19061
{code}
But What i am looking is like this.
{code}
22767 19093 19095 19049 19049 19059
22767 19060
22767 19093 19095 19062 19062 19060
22767 19061
22768 19094 19093 19062 19062 19060
22768 19061
{code}
Please help.
Hi,
Could you please illuminate our minds and spend a bit of time in explaining the logic? That will be much easier without reading the crystal ball which nobody has it here.
Please read: Re: 2. How do I ask a question on the forums?
And please provide sample data (create table and insert statement), description of the logic, database version and everything else which is specified in the FAQ
Regards.
Al
Similar Messages
-
Need help for SQL Query last 5 mins Records.
I need the data between the last five minutes from a table which contains Timeid Column and data type is date.
select sysdate,(sysdate-((mod(extract(minutes from systimestamp),5)+5)/24/60)-((extract(second from systimestamp))/24/60/60)) Start_date,
(sysdate-((mod(extract(minutes from systimestamp),5))/24/60)-((extract(second from systimestamp))/24/60/60)) End_Date;
Suppose now the current time is 01:20:00PM then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:00 10/18/2007 01:10:01 10/18/2007 01:15:00
Suppose now the current time is 01:20:01 then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:15:01 10/18/2007 01:20:00
The output i am getting where as i need the output shown above.
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:14:59 10/18/2007 01:19:59SQL> select sysdate,
2 sysdate -
3 (decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
4 mod(to_number(to_char(sysdate,'sssss')),300))+300)/(24*60*60 )
5 st_time,
6 sysdate -
7 decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
8 mod(to_number(to_char(sysdate,'sssss')),300))/(24*60*60 )
9 end_time
10 from dual;
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:46 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:59 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:00 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:01 18-oct-2007 16:35:00 18-oct-2007 16:40:00 -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
hii All
I need help for pl/sql function.
I build a function for monthly attendance all employees.
but now i want to show all Sundays with 'S' and others respectively 'P' and 'A'.
Currently Sunday also shows 'A'
So please help
SQL queries ... like
SELECT DISTINCT AL.USERNAME,
CASE WHEN DAY1 =1 THEN 'P' ELSE 'A' END DAY1,
CASE WHEN DAY2 =1 THEN 'P' ELSE 'A' END DAY2,
CASE WHEN DAY3 =1 THEN 'P' ELSE 'A' END DAY3,
CASE WHEN DAY31 =1 THEN 'P' ELSE 'A' END DAY31
FROM
SELECT DISTINCT USERNAME, SUM(CASE WHEN
fromdt=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY1
,SUM(CASE WHEN
fromdt +1=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY2,
SUM(CASE WHEN
fromdt+30=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY31
FROM ( SELECT DISTINCT TRUNC(LOGIN_DATE)LOGIN_DATE ,USERNAME FROM FCDM_AUDIT_TRAIL_NEW WHERE
TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
-- to_date( login_date, 'dd-mom-yyyy') between to_date( fromdt, 'dd-mom-yyyy') and to_date( todt, 'dd-mom-yyyy')
) L
GROUP BY USERNAME
) AL;
how can i show matched Sundays and show with 'SUN' or 'S'
Regards
vij..Try this way:
SELECT USERNAME,
MAX(CASE WHEN to_char(fromdt,'d')='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt,'d')!='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY1,
MAX(CASE WHEN to_char(fromdt+1,'d')='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt+1,'d')!='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY2,
MAX(CASE WHEN to_char(fromdt+30,'d')='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt+30,'d')!='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY31
FROM
(SELECT DISTINCT TRUNC(LOGIN_DATE) LOGIN_DATE,
USERNAME
FROM FCDM_AUDIT_TRAIL_NEW
WHERE TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
) L
Group by USERNAME
;Max
http://oracleitalia.wordpress.com -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
Hi all,
I have data in the following manner:
CASE_NUMBER HOURS FLAG
1000 10 0
1000 20 0
1000 30 1
1000 40 0
1000 50 1
Here I need to Calculate the total hours for a Case_number till i see the flag as 1.
Here the result must be 10+20+30 Hrs
Another Example
CASE_NUMBER HOURS FLAG
2000 10 1
2000 20 1
Here the result must be only 10.
I am struggling to write a SQL query for this.
Anyones help will be very much greatful
Thanks in Advance
Regards,
Sengathir SubbarayanLook up analytical functions.
something like sum(hours) OVER (PARTITION BY case_number ORDER BY something)
will give you the sum for all rows.
Then you probably want to "throw away" those rows after the flag maybe by summing the flag column too, and throw away all those where the flag is greater than 1 and where it is equal to 1 except for the first one.
I suspect you actually have some other column (other than the number of hours) that define your order - that's what you put in the ORDER BY.
Jon -
I have a table with Columns as as below
id number primary key
object_name varchar2(100)
object_value varchar2(100)
Data is stored as follows
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
80 Misc 3 desc
SQL should return result as shown below
id object_name object_value
10 prop_num 436
20 city dallas
40 min amount 90
50 interest amount 700
I have done this through plsql code by creating temp table. But I need to do it in a sql query. I am stuck here
Any pointers/help is appreciated
Thanks
Edited by: user9327712 on Mar 11, 2010 8:14 AMI have a table where the ids are stored.
*"object name"* column values are actually another table columns stored as rows here. So in our example prop_num, city,Misc 1, Misc 1 desc, Misc 2, Misc 2
desc,Misc 3 , Misc 3 desc are all columns. These would not change any time
The column object_value has values stored for respective columns.
436, dallas , 90 , min amount , 700 , interest amount are all column values. So these can change.
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
90 Misc 3 desc
Edited by: user9327712 on Mar 11, 2010 9:57 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM -
Hi Friends,
I am too muchconfused about an sql query. I've created a html page where I select one radio button . The value of this radio button is passed to the query.Now the out put of the query is used in developing the output.
For illustration I show you the source code.
Radio Button Selection page.
<form action="service.html" method="post"> <h3><strong>Services Available</strong></h3> <p> <label> <input type="radio" name="service" value="si" /> Institutions</label> <br /> <label> <input type="radio" name="service" value="sc" /> Corporate_Offices</label> <br /> <label> <input type="radio" name="service" value="sr" /> Restaurent_Cafe</label> <br /> </p> <label> <input type="submit" value="Submit" /> </label> </form>
Now the query page-
<sql:query var="empList" scope="session"> select <c:out value="${param.service}" /> from map_service where cityname = ? <sql:param value="${param.cityname}" /> </sql:query>
Now I need to generate output with the given below value in the next page-
<c:out value="${param.service}" />
This value show value as si, sc sr only where I need the database table value as per selection.
I am really confused that what I should write as <c:out value="${...
My database table has attributes as cityname, si, sc, sr. etc.
when some one select si from radio button the value of radio button is passed to sql query and the value which is selected on the table after query should be used in developing output result please help.Dear Friend Is it not possible for any of you to give me a clue that if I've to get the output of *?* from the query what I can write in syntax.
<sql:query var="empList" scope="session">
select ? from map_service
where cityname = ?
<sql:param value="${param.service}" />
<sql:param value="${param.cityname}" />
</sql:query>
<c:out value="${empList.param.service}" />Output of the value of ? from the database select ? from map_service Any idea -
Complete novice needs help getting SQL Query into Crystal Reports XI
Post Author: MissMarnie
CA Forum: Data Connectivity and SQL
So I was given an intro level web course and a monster reference guide in prep to format a report. One of our developers wrote me everything I need for the report into a SQL Query and now I'm supposed to format it in CR XII literally do not know what to do from here. I'm able to set up the correct server as a datasource, if that's useful, but I don't know how to make the querey into a bunch of formattable fields in CR. If anyone can walk me through this, I'd be so grateful. I've attempted to look up SQL query in both the help and the book but I keep hitting a wall. The help dialog says things like "press this button" with no reference to what "this button" is. I'm sure it's obvious to the knowledgeable but I'm in a complete fog. Thanks in advancePost Author: synapsevampire
CA Forum: Data Connectivity and SQL
IF you're trying to get assistance with setting up a query as the source for a report, try posting your Crystal version and the database type.
Different software works differently.
In CR 9 and above, under the connection to the database you'll see Add Command. Select that and you can paste the query in.
As for not knowing how to generate a report, that requires experience, there's no generic solution of course..
-k -
I am trying to build a query that sums up 12 columns depending on some accounting variables.
example:
SELECT gbmcu, gbco, gbfy,'',SUM(gban01 gban02 gban03 gban04 gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12) AS Oil_Volumes
FROM PRODDTA.F0902
WHERE GBCO = '00099'
AND GBFY = 5
AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
GROUP BY gbmcu, gbco, gbfy
The condition that changes is :AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
I need to do this for 17 different conditions - I need to make the query as optimized as possible.
I tried using a case statement but that takes forever (the table is over 4 million records to scan through).
Please let me know if anyone has any suggestions on how to create something to perform these calculations.
thanks,
PamI think I would tend to write that query as:
SELECT gbmcu, gbco, gbfy,
SUM(CASE WHEN gblt = 'QA' AND gbobj = 5015 AND gbsub = '105' THEN
gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Sales
SUM(CASE WHEN gblt = 'QU' AND gbobj = 5015 AND gbsub = '105' THEN
gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Volumes
FROM proddta.f0902
WHERE gbco = '00099' and
gbfy = 5 and
gblt IN ('QA', 'QU') and
gbpbj = 5015 and
gbsub = '105'
GROUP BY gbmcu, gbco, gbfySUM the CASE rather than CASE SUM. Also, as written, your query will look at all of the records in f0902 whether or not they meet one of the Case criteria, so I would put the required values in the WHERE clause as well. Your samples only show gblt changing, so you may need to make the gbpbj and gbsub predicates IN lists as well.
If the query runs in 1.5 hours calculating one value, I would expect it to be about the same calculating 17 values, since I would bet that most of the run time is accessing the table rather than doing the math. It would almost certainly be faster than running essentially the same query 17 times.
Indexes on some or all of the columns in the WHERE clause may help, depending on how selective the columns are. At a guess, I would suggest that gbco and gbfy would be good candidates.
Finally, are you sure that gbsub is a character field? The only example we have is a number.
HTH
John -
Hi,
Need help to write sql statement.
create table t_dt ( dt_start date, dt_end date, amount number);
insert into t_dt values('1-Jan-10','10-Feb-10',12);
insert into t_dt values('11-Feb-10','10-Mar-10',10);
insert into t_dt values('11-Mar-10','20-Apr-10',8);
insert into t_dt values('21-Apr-10','28-Jun-10',10);
insert into t_dt values('29-Jun-10','20-Sep-10',10);
insert into t_dt values('21-Sep-10','10-Oct-10',10);
insert into t_dt values('11-Oct-10','31-Dec-10',8);
insert into t_dt values('1-Jan-11','10-Feb-11',8);
insert into t_dt values('11-Feb-11','10-Mar-11',7);
insert into t_dt values('11-Mar-11','20-Apr-11',6);
insert into t_dt values('21-Apr-11','28-Jun-11',6);
insert into t_dt values('29-Jun-11','20-Sep-11',6);
insert into t_dt values('21-Sep-11','10-Oct-11',4);
insert into t_dt values('11-Oct-11','31-Dec-11',8);
Result should be like below..
dt_start dt_end Amount
1-Jan-10 10-Feb-10 12
11-Feb-10 10-Mar-10 10
11-Mar-10 20-Apr-10 8
21-Apr-10 10-Oct-10 10
11-Oct-10 10-Feb-11 8
11-Feb-11 10-Mar-11 7
11-Mar-11 20-Sep-11 6
21-Sep-11 10-Oct-11 4
11-Oct-11 31-Dec-11 8
Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
Thanks.Hello
I think this gives yuo what you need....
SELECT
MIN(dt_start),
MAX(dt_end),
amount
FROM
( SELECT
dt_start,
dt_end,
MAX(marker) OVER(ORDER BY dt_start) marker,
amount
FROM
Select
dt_start,
dt_end,
amount,
CASE
WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
ROW_NUMBER() OVER(ORDER BY dt_start)
END marker
from t_dt
GROUP BY
amount,
marker
order by
MIN(dt_start)
MIN(DT_START) MAX(DT_END) AMOUNT
01-JAN-2010 00:00:00 10-FEB-2010 00:00:00 12
11-FEB-2010 00:00:00 10-MAR-2010 00:00:00 10
11-MAR-2010 00:00:00 20-APR-2010 00:00:00 8
21-APR-2010 00:00:00 10-OCT-2010 00:00:00 10
11-OCT-2010 00:00:00 10-FEB-2011 00:00:00 8
11-FEB-2011 00:00:00 10-MAR-2011 00:00:00 7
11-MAR-2011 00:00:00 20-SEP-2011 00:00:00 6
21-SEP-2011 00:00:00 10-OCT-2011 00:00:00 4
11-OCT-2011 00:00:00 31-DEC-2011 00:00:00 8
9 rows selected.HTH
David
Edited by: Bravid on Feb 23, 2012 12:08 PM
Beaten to it by Frank! :-) -
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 balthropbregent,
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. -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
Need help with sql query dates
Hi,
I have a sql query where i need to extract some info between given dates. The where clause of this query is as follows:
WHERE CPD_BUS_UNIT=:ESI_PRM_1
AND CPD_VOUCHER_DATE >= :P_DATE_FROM
AND CPD_VOUCHER_DATE < (:P_DATE_TO+1)
When i execute the query in toad, i can view the data but not the execution plan.It gives an error ORA-00932-Inconsistent Datatypes.
But when i remove (+1) from :P_DATE_TO, i can c the execution plan and data. Will the data be different from the previous one.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1
AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM)
AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1) Regards -
Hi,
I have a client requirement to show a report on the device availability. The report should show the output as
Node Availability%
Formula for Availability = (Total No. of Failed/Total No. rows) * 100
My Oracle Table has the following data
NODE SUMMARY
172.16.10.55 Default Interface Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Interface Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Chassis Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Interface Ping restore for 172.16.10.55
172.16.10.55 Default Interface Ping fail for 172.16.10.55: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Interface Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Chassis Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Interface Ping fail for 172.16.10.56: ICMP timeout
In the above table the Summary column has the details like 'Ping fail' , 'Ping restore' for each Node. So, for each Node I have to compute the Total Ping Fail / (Total Ping Fail + Ping Restore) * 100 to compute the availability %.
My output should be like the below
Node Availability%
172.16.10.55 55.55
172.16.10.56 54
Can someone please help me with query.
I appreciate your help in advance.
Thanks.
Regards,
RaviShankar.My Oracle Table has the following dataThat's great, but if you want maximum response to your question, then post CREATE TABLE + INSERT INTO statements.
I currently do not have the time to turn your data into them.
And always post the database version you're using.
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
Also use the {noformat}{noformat} tag in order to post examples that benefit from staying formatted and thus readable when posted on the forum.
Simply put the tag before and after your examples.
For example, when you type:
{noformat}select *
from dual;{noformat}
it will appear as:select *
from dual;
Maybe you are looking for
-
My music won't show up on my iPhone
I purchased music on a 4 about a week ago, shared it to my iPad (which worked just one) through iCloud. I fell when I was on a run and busted my phone so had to get a new one and got a 4s. I went to share my music and it appeared to be downloading to
-
Where can I get an APK file to install Firefox Beta? I don't use Google Play.
I'd like to test Firefox Beta but I can't seem to find a direct link to download the APK installer. It seems to be only available from Google Play but I prefer not to use proprietary software on my devices. My test devices are Galaxy SIII and Kobo Ar
-
How to define the PATH of Xquartz?
The PATH predefined within Xquartz is:<pre> PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin </pre> How may I change it? dan
-
How do I Send a xml to client?
Hi friends: It is possible to send a xml to client without a xml file in the server? I create a Document in the server and the code is : DocumentBuilderFactory df=DocumentBuilderFactory.n
-
Standalone Scenario (need info about Plants)
Hi, i am working now with SRM standalone scenario. It means that now i don't have any back-end systems. All that i need is to maintain all necessary business-process localy in EBP. i have such questions: 1.if i have no back-end system, how should i m