URgent: Help regarding SQL Query
Hi ,
I need help regarding an sql query.
Sample Data:
ITEM_TYPE ITEM_NUM UNIT_PRICE QUANTITY LINE_TOTAL
ITEM 1 5 10 50
ITEM 2 10 5 50
ITEM 1 5 5 25
ITEM 2 10 20
TAX 16.5
TAX -3.5I would like to display the data as
ITEM_TYPE ITEM_NUM UNIT_PRICE QUANTITY LINE_TOTAL
ITEM 1 5 15 145
2 10 5
2 10
TAX 13.0
Line_total = unit_price * QuantityThanks in Advance
G.Vamsi Krishna
Edited by: user10733211 on Aug 5, 2009 7:42 AM
Edited by: user10733211 on Aug 5, 2009 7:49 AM
Edited by: user10733211 on Aug 5, 2009 8:12 AM
Edited by: user10733211 on Aug 5, 2009 8:22 AM
Edited by: user10733211 on Aug 5, 2009 8:24 AM
Hi,
Try this, use some analytics:
SQL> with t as (
2 select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
3 select 'item', 2, 10, 5, 50 from dual union all
4 select 'item', 1, 5, 5, 25 from dual union all
5 select 'item', null, 2, 10, 20 from dual union all
6 select 'tax', null, null, null, 16.5 from dual union all
7 select 'tax', null, null, null, -3.5 from dual
8 ) -- actual query starts here:
9 select item_type
10 , item_num
11 , unit_price
12 , sum_qty
13 , case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
14 then null
15 else sum_lt
16 end sum_lt
17 from ( select item_type
18 , item_num
19 , unit_price
20 , quantity
21 , sum(quantity) over ( partition by item_type, item_num ) sum_qty
22 , sum(linetotal) over ( partition by item_type ) sum_lt
23 , row_number() over ( partition by item_type, item_num order by item_type, item_num ) rn
24 from t
25 )
26 where rn=1;
ITEM ITEM_NUM UNIT_PRICE SUM_QTY SUM_LT
item 1 5 15 145
item 2 10 5
item 2 10
tax 13
4 rows selected.
edit
And please use the code tag, instead of clunging with concats.
Read:
http://forums.oracle.com/forums/help.jspa
Edited by: hoek on Aug 5, 2009 5:15 PM
edit2
Also nulls for item_type:
ops$xmt%OPVN> with t as (
2 select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
3 select 'item', 2, 10, 5, 50 from dual union all
4 select 'item', 1, 5, 5, 25 from dual union all
5 select 'item', null, 2, 10, 20 from dual union all
6 select 'tax', null, null, null, 16.5 from dual union all
7 select 'tax', null, null, null, -3.5 from dual
8 ) -- actual query starts here:
9 select case when item_type = lag(item_type) over ( order by item_type, item_num )
10 then null
11 else sum_lt
12 end item_type
13 , item_num
14 , unit_price
15 , sum_qty
16 , case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
17 then null
18 else sum_lt
19 end sum_lt
20 from ( select item_type
21 , item_num
22 , unit_price
23 , quantity
24 , sum(quantity) over ( partition by item_type, item_num ) sum_qty
25 , sum(linetotal) over ( partition by item_type ) sum_lt
26 , row_number() over ( partition by item_type, item_num order by item_type, item_num ) rn
27 from t
28 )
29 where rn=1;
ITEM_TYPE ITEM_NUM UNIT_PRICE SUM_QTY SUM_LT
145 1 5 15 145
2 10 5
2 10
13 13
4 rows selected.If you really need a space instead of nulls, then simply replace the nulls by a space....
Edited by: hoek on Aug 5, 2009 5:18 PM
Similar Messages
-
Very Urgent Help , ABAP SQL Query
Guys,
Please suggest.I have a table(custom_table1) with a field say A which is of date type = c and length = 9. And i want to query this table.Following is the query.
Select substr(A,0,5) B C into itab From table custom_table1
where b = ( select b from cusstom_table2 )
and substr(A,0,5) = Input_A.
That is i want to equate an Input_A (which is of 5 character length) with field A (only first 5 character of the 9 length). But it seems the query is wrong. Kindly help ,very urgent
ThanksThanks guys, U have helped me to fill up the where condition as
but what about the column A in the select query ?I need only 5 characters from the field populated into Itab.
CONCATENATE srch_str '%' INTO srch_str. -- bcos i want it to be 'InputA%'
Select Substr(A,0,5) , B C Into Itab From CustomTable 1 where B = (Select B from customtable2) and A Like SrchStr
Is there any means i can populate only the 5 characters from the select field A into Itab without using Substr (becos it doesnt work) ? Please help. -
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 -
I have a column with values
Sample Data
EMPNO
=====
1
2
3
4
5
6
7
8
.I would like to display all the values of the column in a single row with multiple columns
I do not want to create any other objects. i require a single query.
Sample Output
col1 col2 col3 col4 col5 col6 col7 col8 ............
=======================================
1 2 3 4 5 6 7 8 ...............FYI i am using Oracle 9.2.0
Thanks in Advance
Edited by: user10733211 on Oct 7, 2009 5:38 AMHmm...
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>with tab
2 as
3 (
4 select 1 cola from dual
5 union all
6 select 2 from dual
7 union all
8 select 3 from dual
9 )
10 select *
11 from tab;
COLA
1
2
3
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>with tab
2 as
3 (
4 select 1 cola from dual
5 union all
6 select 2 from dual
7 union all
8 select 3 from dual
9 )
10 select sum(decode(cola,1,1,0)) col1,
11 sum(decode(cola,2,2,0)) col2,
12 sum(decode(cola,3,3,0)) col3
13 from tab;
COL1 COL2 COL3
1 2 3
Elapsed: 00:00:00.00
satyaki>
satyaki>decode can be used in much more complex case - i guess. ;)
Regards.
Satyaki De. -
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. -
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 -
Hi,
I need a help in writing an SQL query . I am actually confused how to write a query. Below is the scenario.
CREATE TABLE demand_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
quantity NUMBER,
order_type NUMBER
CREATE TABLE order_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
open_flag VARCHAR2(10)
INSERT INTO demand_tmp
SELECT 12438,82,821,100,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,849,350,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,NULL,150,29 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,0,50,-1 FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,821,'Y' FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,849,'N' FROM dual;
Demand_tmp:
Item_id org_id order_line_id quantity order_type
12438 82 821 100 30
12438 82 849 350 30
12438 82 NULL 150 29
12438 82 0 50 -1
Order_tmp :
Item_id org_id order_line_id open_flag
12438 82 821 Y
12438 82 849 N I need to fetch the records from demand_tmp table whose order_line_id is present in order_tmp and having open_flag as 'Y' or if order_type in demand_tmp table is 29.
The below query will give the records whose order line id is present in order_tmp. But, If i need records which are having order_type=29 the below query wont return any records as order_line_id is NULL. If I place outer join I will get other records also (In this example order_type -1 records) . Please help me how can we write a query for this. Expected o/p is below.
Query :
Select item_id,org_id,order_line_id,quantity,order_type,open_flag
from demand_tmp dt , order_tmp ot
where dt.order_line_id = ot.order_line_id
AND dt.item_id=ot.item_id
AND dt.org_id = ot.org_id
AND ot.open_flag = 'Y';
Expected Output :
item_id org_id order_line_id quantity order_type open_flag
12438 82 821 100 30 Y
12438 82 NULL 150 29 NULL Thanks in advance,
Rakesh
Edited by: Venkat Rakesh on Oct 7, 2012 6:32 PM
Edited by: Venkat Rakesh on Oct 7, 2012 8:39 PMHi Rakesh,
the query is not working as you would like ( but IS working as expected ) since your trying to compare null to another value.
Comparing null always results in FALSE, also if you compare null to null. This is because null means undefined.
select 1 from dual where null=null results in no data found.
I would suggest using a non natural key to join the tables.
For example include a column ID in the master table which is filled with a sequence and include that field as a foreign key in the detail table.
This way you can easily join master and detail on ID = ID, and you don't have to worry about null values in this column since it's always filled with data.
Regards,
Bas
btw, using the INNER JOIN and OUTER JOIN syntax in your SQL makes it better readable, since you're separating join conditions from the where clause, just a tip ;) -
HELP! SQL Query: Other ways to reorder column display?
I have a SQL query report with a large number of columns (users can hide/show columns as desired). It would be great if the column display order could be changed by changing the order of the columns in the SELECT list in the Report Definition, but that doesn't work -- it puts changed or added columns at the end regardless of the order in the SELECT list of the query.
Is there some other way to reorder the columns displayed without using the Report Attributes page? It's extremely tedious to move columns around using the up/down arrows which redisplays the page each time. Am I missing a way to change display order, or does anyone have a "trick" to do this? It's so painful....
When defining forms you can reoder columns by specifying a sequence number for each column. Just curious as to why reports were not done the same way, and are there any plans to address this in a future release?
KarenYes, reordering columns is extremely painful.
It is supposed to be much improved in the next version.
See
Re: Re-ordering columns on reports
Moving columns up/down in Report Attributes
See my example at
http://htmldb.oracle.com/pls/otn/f?p=24317:141
Basically, let the users move columns around until they are blue in the face, provide a Save button to save the column order in a user preference and reorder the columns when the page reloads.
Or you can use Carl's PL/SQL shuttle as the widget to specify the columns shown and their order. The shuttle is at http://htmldb.oracle.com/pls/otn/f?p=11933:27
Hope this helps.
Message was edited by:
Vikas -
Help with sql query the status of A/P Reserve Invoice
Hi,
I am trying to write a query which lists all A/P Reserve Invoice info with OPEN status.
I check the OPCH table and cannot find the rule to tell the status.
The "DocStatus" field has two values only: 'O' for open and 'C' for closed.
However, the status of A/P Reserve Invoice are OPEN, CLOSED, DELIVERED, PAID, etc.
I try to use DocStatus field to filter, but the result does not match what I see in SAP.
Could you please give me some hints about how to get the data I need? Thank you.
Best regards,
Sylvia
Edited by: csylvia on Jun 23, 2011 5:54 AMHi Darius,
Thanks for your reply.
However, I don't know what is the relationship between Purchase order and A/P Reserve Invoice.
Do you mean using "SELECT T0.DocEntry FROM OPCH T0, OPOR T1 WHERE T0.DocNum = T1.DocNum AND T1.DocStatus = 'O';" to query the A/P Reserve Invoice data with OPEN status?
But the result is not what I want.
The result of "*SELECT * FROM OPOR WHERE DocStatus = 'O';*" is also not.
I'd like to query A/P Reserve Invoice list with OPEN status, and I try the following sql query:
SELECT DocEntry FROM OPCH WHERE DocStatus = 'O' AND InvntSttus = 'O';
The result is close to what I need, but it's not exactly correct.
Moreover, I don't think the sql query conditions is accurate.
Please give me some advice. Thank you.
Best regards,
Sylvia -
VERY URGENT: problem in sql query with long datatype in weblogic
I have a problem while tryind to retrieve a column value with a long datatype using servlet and oci driver and the server is weblogic5.1 .I have used prepared statement the problem comes in the
preparedStatement.executeQuery().
The sql Query is simple query and runs well in all cases and fails only when the long datatype column is included in the query.
The exception that comes on the weblogic server is that :
AN UNEXPECTED EXCEPTION DETECTED IN THE NATIVE CODE OUTSIDE THE VM.Did you try changing the driver then?
Please use Oracle's thin driver instead of the oci driver.
There are many advantages of using the type 4 driver. the first and foremost being that it does not require oracle client side software on your machine. Therefore no enteries to be made in tnsnames.ora
The thin driver is available in a jar called classes112.zip the class which implements the thin driver is oracle.jdbc.driver.OracleDriver
the connection string is
jdbc:oracle:thin:@<machine name>:1521:<sid>
please try out with the thin driver and let me know.
regards,
Abhishek. -
Help with SQL query invloving time operations
I have created 2 tables in my SQL. One is the user_info table which stores the time of login and timezone of login for each user. The other is the post_table which stores the postid, user who makes the post, time of post and timezone for each posts.
CREATE TABLE user_info
user_id VARCHAR(20),
login_date DATE,
login_time_zone VARCHAR(20),
PRIMARY KEY (user_id)
CREATE TABLE post_table
post_id VARCHAR(20),
user_id VARCHAR(20),
datepost DATE,
time_zone VARCHAR(20),
PRIMARY KEY (post_id),
FOREIGN KEY (user_id) REFERENCES user_info(user_id) ON DELETE CASCADE
) ;Some sample data for my tables is as below -
INSERT INTO user_info VALUES( 'u1', to_date('9/17/2009 20:00','MM/DD/YYYY mi:ss'), -2 );
INSERT INTO user_info VALUES( 'u2', to_date('9/17/2009 19:55','MM/DD/YYYY mi:ss'), -4 );
INSERT INTO post_table VALUES( 'p1', 'u1', to_date('9/17/2009 20:50','MM/DD/YYYY mi:ss'), 6 );
INSERT INTO post_table VALUES( 'p2', 'u2', to_date('9/17/2009 20:30','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO post_table VALUES( 'p3', 'u2', to_date('9/18/2009 6:00','MM/DD/YYYY mi:ss'), 2 );
INSERT INTO post_table VALUES( 'p4', 'u1', to_date('9/17/2009 21:00','MM/DD/YYYY mi:ss'), -3 );I need to write an SQL query which - finds the user(s) whose time difference between the login time and the latest time when he/she writes a post is the smallest. I need to consider the timezones here as well.
I am unsure if time_zone should be of type VARCHAR or TIMESTAMP so have created it as VARCHAR in my tables.
Someone please help me form this query.
PS : How do I user <code> tags in this forum to write sql statements.
Edited by: user11994430 on Oct 9, 2009 5:59 PMI tried with the following test data
INSERT INTO user_info VALUES( 'u1', to_date('9/17/2009 20:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u2', to_date('9/16/2009 13:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u3', to_date('9/18/2009 15:00','MM/DD/YYYY mi:ss'), 0 );
INSERT INTO user_info VALUES( 'u4', to_date('9/20/2009 17:00','MM/DD/YYYY mi:ss'), 0 );
INSERT INTO user_info VALUES( 'u5', to_date('9/14/2009 3:00','MM/DD/YYYY mi:ss'), -3 );
INSERT INTO user_info VALUES( 'u6', to_date('9/15/2009 6:00','MM/DD/YYYY mi:ss'), -3 );
INSERT INTO user_info VALUES( 'u7', to_date('9/16/2009 7:00','MM/DD/YYYY mi:ss'), 0 );
INSERT INTO user_info VALUES( 'u8', to_date('9/17/2009 8:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u9', to_date('9/18/2009 9:00','MM/DD/YYYY mi:ss'), 0 );
INSERT INTO user_info VALUES( 'u10', to_date('9/19/2009 10:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u11', to_date('9/20/2009 11:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO user_info VALUES( 'u12', to_date('9/21/2009 19:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u13', to_date('9/1/2009 4:00','MM/DD/YYYY mi:ss'), -3 );
INSERT INTO user_info VALUES( 'u14', to_date('9/22/2009 7:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u15', to_date('9/24/2009 23:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u16', to_date('9/25/2009 11:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u17', to_date('9/26/2009 18:00','MM/DD/YYYY mi:ss'), -4 );
INSERT INTO user_info VALUES( 'u18', to_date('9/27/2009 13:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u19', to_date('9/17/2009 18:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO user_info VALUES( 'u20', to_date('9/29/2009 22:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u21', to_date('9/30/2009 5:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u22', to_date('9/15/2009 7:00','MM/DD/YYYY mi:ss'), -4 );
INSERT INTO user_info VALUES( 'u23', to_date('9/16/2009 17:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO user_info VALUES( 'u24', to_date('9/17/2009 19:00','MM/DD/YYYY mi:ss'), 0 );
INSERT INTO user_info VALUES( 'u25', to_date('9/18/2009 22:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO user_info VALUES( 'u26', to_date('9/19/2009 15:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO user_info VALUES( 'u27', to_date('9/20/2009 23:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES('p1', 'u26', to_date('9/14/2009 18:00','MM/DD/YYYY mi:ss'), -5 ) ;
INSERT INTO post_table VALUES('p2', 'u2', to_date('7/1/2009 15:00','MM/DD/YYYY mi:ss'), 1 ) ;
INSERT INTO post_table VALUES('p3', 'u2', to_date('7/20/2009 20:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES('p4', 'u5', to_date('7/20/2009 22:00','MM/DD/YYYY mi:ss'), 1) ;
INSERT INTO post_table VALUES( 'p5', 'u2', to_date('7/21/2009 10:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES( 'p6', 'u8', to_date('8/1/2009 20:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO post_table VALUES( 'p7', 'u10', to_date('5/3/2009 15:00','MM/DD/YYYY mi:ss'), -3 ) ;
INSERT INTO post_table VALUES( 'p8', 'u25', to_date('9/15/2009 20:00','MM/DD/YYYY mi:ss'), -5 ) ;
INSERT INTO post_table VALUES( 'p9', 'u6', to_date('9/7/2009 19:00','MM/DD/YYYY mi:ss'), -3 ) ;
INSERT INTO post_table VALUES( 'p10', 'u10', to_date('7/22/2009 10:00','MM/DD/YYYY mi:ss'), 1 ) ;
INSERT INTO post_table VALUES( 'p11', 'u9', to_date('7/7/2009 13:00','MM/DD/YYYY mi:ss'), 0) ;
INSERT INTO post_table VALUES( 'p12', 'u2', to_date('7/30/2009 11:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES( 'p13', 'u10', to_date('7/22/2009 8:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES( 'p14', 'u6', to_date('5/30/2009 23:00','MM/DD/YYYY mi:ss'), 1 );
INSERT INTO post_table VALUES( 'p15', 'u3', to_date('5/31/2009 2:00','MM/DD/YYYY mi:ss'), 0 ) ;
INSERT INTO post_table VALUES( 'p16', 'u12', to_date('6/20/2009 7:00','MM/DD/YYYY mi:ss'), -8 ) ;
INSERT INTO post_table VALUES( 'p17', 'u20', to_date('6/20/2009 9:00','MM/DD/YYYY mi:ss'), -8) ;
INSERT INTO post_table VALUES( 'p18','u27', to_date('9/15/2009 11:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO post_table VALUES( 'p19','u26', to_date('7/1/2009 20:00','MM/DD/YYYY mi:ss'), 0 ) ;
INSERT INTO post_table VALUES( 'p20', 'u25', to_date('7/2/2009 17:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO post_table VALUES( 'p21', 'u27', to_date('7/3/2009 20:00','MM/DD/YYYY mi:ss'), 1) ;
INSERT INTO post_table VALUES( 'p22', 'u2', to_date('9/15/2009 13:00','MM/DD/YYYY mi:ss'), 1 ) ;
INSERT INTO post_table VALUES( 'p23', 'u21', to_date('5/30/2009 17:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO post_table VALUES( 'p24', 'u25', to_date('8/30/2009 20:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO post_table VALUES( 'p25', 'u18', to_date('9/13/2009 18:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO post_table VALUES( 'p26', 'u11', to_date('9/9/2009 13:00','MM/DD/YYYY mi:ss'), -8 );
INSERT INTO post_table VALUES( 'p27', 'u23', to_date('9/10/2009 1:00','MM/DD/YYYY mi:ss'), -5 );
INSERT INTO post_table VALUES( 'p28', 'u22', to_date('9/10/2009 14:00','MM/DD/YYYY mi:ss'), -4 );The output I get is
USER_ID
u25
u9
u20
u5
u27
u8
u21
u23
u22
u26
u10
USER_ID
u3
u12
u18
u2
u6
u11
17 rows selected. -
Help with SQL query into Crystal
Afternoon all,
I am trying to convert the following SQL query into Crystal by using the tables given in the query however the relationship given in the query is bit awkward, in a sense that I cannot create a relationship under Crystal desgin.
Here is the query
select count(order_progressed.order_no),reason_code
from order_progressed,lab_reasons, rework_groups
where
order_progressed.date_created=Today
and (order_progressed.order_status=from_gate
and lab_reasons.reason_code between from_reason and to_reason)
group by lab_reasons.reason_code
order by 2
We have three tables
1: Order_Progressed
2: Lab Reasons
3: Rework_Groups
Order_progressed can be linked with rework_group by Status (if you see the line order_progressed.order_status=from_gate)
However how to link the following line?
lab_reasons.reason_code between from_reason and to_reason
I mean when I try to link it by Lab Reasons.Reason Code to From_reason, to reason, it doesn't seem to work.
The report is grouped by Lab Reasons. Reason Code, so I really have to some how create a relationship between Lab Reasons table and Rework_Group table.
This is what I get when I run the same query into Crystal using the relationship
SELECT lab_reasons.reason_code, order_progressed.date_created, order_progressed.order_no
FROM maxmast.lab_reasons lab_reasons, kevin.order_progressed order_progressed,
roger.rework_groups rework_groups
WHERE (order_progressed.order_status=rework_groups.from_gate) AND
((lab_reasons.reason_code=rework_groups.from_reason) AND
(lab_reasons.reason_code=rework_groups.to_reason)) AND (order_progressed.date_created>={ts
'2008-01-01 00:00:00'} AND order_progressed.date_created<={ts '2008-12-17 00:00:00'})
Any ideas?
Many thanks
Kind Regards
JehanzebSastry I didn't understand why did you use Lab_reasons.reason_code twice in your SQL.
What I have done since I posted this thread,
I created a command like this
Select *
from rework_groups,lab_reasons
where
lab_reasons.reason_code between from_reason and to_reason
Then I took out the lab_reasons table and rework_groups table, then I linked the order_status from Order_progressed table to From_gate of the newly created table (I called it Reason_Code).
This made the report running but it is crunching quite allot of numbers. I wonder if I made a mistake somewhere?
Oh and please note, I'd like to create an SQL (if need be) without the date entry which was done in the original SQL because I'd like to setup my own date range within Crystal Reports instead of getting passed by SQL itself.
This is how it looks like in Crystal now.
sae1_live
SELECT order_progressed.date_created, order_progressed.order_no, order_progressed.order_status
FROM kevin.order_progressed order_progressed
WHERE (order_progressed.date_created>={ts '2008-01-01 00:00:00'} AND
order_progressed.date_created<={ts '2008-12-17 00:00:00'})
EXTERNAL JOIN order_progressed.order_status={?sae1_live: Reason_Code.from_gate}
sae1_live
Select *
from rework_groups, lab_reasons
where lab_reasons.reason_code between from_reason and to_reason
EXTERNAL JOIN Reason_Code.from_gate={?sae1_live: order_progressed.order_status}
Regards
Jehanzeb -
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; -
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. -
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
Maybe you are looking for
-
HI, In flat file extraction my Business Scenario is Enhancements to the BI-located GL Account Master Data Table In the NW Natural context the Unit of Measure and Statistical Key Figure Type values are GL Account-specific. In data source maintain scre
-
How secure is redaction in adobe acrobat x pro? Can text be read once redacted?
I have redacted and applied all the credit card info from some pdfs and saved them after. Is there any way of undoing the redaction and being able to read the credit card info. Your experience in this field will be much appreciated. KF.
-
How to make a fill-in form in pdf?
I would like to make a pdf contract that clients can easily fill in and email back to me. Is this possible in Photoshop?
-
Purchase Order Release Strategy - Emails/SOST
Hi, Please bear with me in terms of knowledge level on this subject, it's not normally my "area" but I'm trying to assist a colleague. When an order reaches a certain value, it requires authorisation by a senior member of staff, from Manager to Direc
-
CS 5.5 Title Aliased After Export
Hello, I have a strange issue with CS 5.5. I have a 3 minute video that has 3 titles in it. All were created with After Effects. One of them however, although it is perfectly smooth within the viewer premiere, becomes aliased and blocky after bein