Help With Querying A Database
Hi,
I have the script below that calculates the total length of phone calls each customer has made and shows the total cost of there phone calls, when this query is displayed i would also like to show the customers phone number as well as the customer id. The customer id is already in the query and working, however when i add cust_area_code to the query, the query runs but it does not display the customers phone number.
select customer.cust_id as "Customer ID"
,sum(calls.elapsed_minutes) as "Total Call Length (Mins)"
,sum(calls.elapsed_minutes*calls.rate) as "Total Cost Of Calls £"
from
(select cust_id
,cust_area_code --- This is the line i have added in
,round((end_date_time-start_date_time)*1440) as elapsed_minutes
,chrg_per_minute as rate
from phonecall
) calls
,customer
where customer.cust_id = calls.cust_id
group by customer.cust_id,calls.cust_id
order by customer.cust_id ascThanks in advance
you don have the cust_area_code in the customer table use joins to link those tables and use it in the first part of the code
select customer.cust_id as "Customer ID",
PHONECALLS.CUST_AREA_CODE as "Phone No"
,sum(calls.elapsed_minutes) as "Total Call Length (Mins)"
,sum(calls.elapsed_minutes*calls.rate) as "Total Cost Of Calls £"
from
(select cust_id
,cust_area_code --- This is the line i have added in
,round((end_date_time-start_date_time)*1440) as elapsed_minutes
,chrg_per_minute as rate
from phonecall
) calls
,customer,
phonecall
where customer.cust_id = calls.cust_id
group by customer.cust_id,calls.cust_id
order by customer.cust_id asc
Message was edited by:
Maran.E
Similar Messages
-
Need Help to query Lync Database for User Information
Need Help to Query the lync database to retrieve below user information.
1. SIP Address of the registered user
2. Phone Number configured to the particular account.
3. IP Address
4. Last Logged in time.
I am trying to pull the above information from rtc database for all the registered users. Please let me know if this is possible and it would be great if you can throw some light on what tables to look for the data. Thank You.Hi,
For SIP address and Phone number you can check RTC database.
IP Address:
You can refer to the link below to query IP address:
http://h30499.www3.hp.com/t5/Business-Service-Management-BAC/Monitoring-Lync-with-the-User-Registrations-Viewer-Free-NMC-tool/ba-p/5961497#.UtOU43mIrwo
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
Last Logged in time:
You can refer to the link below:
http://blogs.technet.com/b/dodeitte/archive/2011/05/11/how-to-get-the-last-time-a-user-registered-with-a-front-end.aspx
Best Regards,
Eason Huang
Eason Huang
TechNet Community Support -
Help with query calculations (recursive)
Hi All,
I want some help with a query using a base rate and the result use in the next calculation year.
Here an example:
create table rate_type(
rate_type_id number,
rate_desc nvarchar2(50),
rate_base_year number
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
create table rates (
rate_type_id number
rate_year number,
rate_value number
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
The result of my sample data is:
2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
NAME 2012 2013 2014
Desc1 5.9149 7.1859 8.4721
Desc2 XXXX XXX XXXX
How can I do this in one select statement? Any ideas?
Thanks!Assuming you are on 11.2:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select *
from (
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
pivot (sum(result) for rate_year in (2012,2013,2014))
order by name
NAME 2012 2013 2014
Desc1 5.914908 7.2918018 8.79388703
Desc2 5.914908 7.2918018 8.79388703
SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
order by name,
rate_year
NAME RATE_YEAR RESULT
Desc1 2012 5.914908
Desc1 2013 7.2918018
Desc1 2014 8.79388703
Desc2 2012 5.914908
Desc2 2013 7.2918018
Desc2 2014 8.79388703
6 rows selected.
SQL> SY. -
Problems with query via Database-Link (Oracle 7.3.4)
I made the following simple query via database-link.
select count (*) from [email protected]
I got the result in about 200 miliseconds.
Then I4ve tried the following query.
select * from [email protected]
It took about 2 hours end ended with an error message "ORA-03113: end-of-file on communication channel"
So I made another choice
select * from [email protected] where rownum <=1
Took about 200 miliseconds.
So I made the query again an changed only the number of rownums,until I was at rownum <=8
then it went sleeping again(I've canceled the statement because I didn't want to wait 2 hours again).
We made the same things from another server with the same database-link on the same remote server
and we had no problems.
Any Idea???No, network is OK!
Other links are running, I have also no problems when I connect directly to the remote server. -
11g: Multicolumn pivot - help with query
Hi everyone,
My first attempt at posting here was not very successful. I have now read the rules, and done more homework.
I'm fairly new to Oracle databases, but have some experience with MySQL and Postgres from earlier.
First of all, here is an example table of what I have today. This is only an extract of the full table, but these fields are the interesting ones.
CREATE TABLE trans
("FROM_LIC" int, "FROM_LOCATION" varchar2(18), "TO_LOCATION" varchar2(18), "CREATE_DT" timestamp)
INSERT ALL
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100002563, '215', 'INN_MONO_05', '04-Mar-2013 11:54:21 AM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100002563, 'INN_MONO_05', 'INN_MONO_06_BANE_R', '04-Mar-2013 11:55:08 AM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100002563, 'INN_MONO_06_BANE_R', 'TROLLEY_19', '04-Mar-2013 12:01:06 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100002563, 'TROLLEY_19', 'UT_OPPLAST_5_2', '04-Mar-2013 12:01:56 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100002563, 'UT_OPPLAST_5_2', 'STG010801', '04-Mar-2013 12:01:56 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003259, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003259, 'INN_MONO_04', 'INN_MONO_04_BANE_L', '04-Mar-2013 02:19:28 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003259, 'INN_MONO_04_BANE_L', 'TROLLEY_5', '04-Mar-2013 02:22:41 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003259, 'TROLLEY_5', 'UT_OPPLAST_3_1', '04-Mar-2013 02:23:35 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003262, '243', 'INN_MONO_06', '04-Mar-2013 01:37:49 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003262, 'INN_MONO_06', 'INN_MONO_06_BANE_R', '04-Mar-2013 01:39:09 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003262, 'INN_MONO_06_BANE_R', 'TROLLEY_10', '04-Mar-2013 01:43:48 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003262, 'TROLLEY_10', 'UT_OPPLAST_5_2', '04-Mar-2013 01:44:58 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003262, 'UT_OPPLAST_5_2', 'STG010904', '04-Mar-2013 01:46:30 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003263, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
VALUES (4100003263, 'INN_MONO_04', 'INN_MONO_04_BANE_R', '04-Mar-2013 02:19:20 PM')
SELECT * FROM dual
;As of now, I have a query that returns a data grid from the table, looking exactly like the example table I've included.
Here is a copy of the query that gives the example table as a result from the table in our database:
select * from (
select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)
union
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)
union
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)
union
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)
union
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)
) order by from_lic, create_dtI would be delighted if you could help me formulating a new query that gives THIS output, from the same table, with the same constraints as in the original query:
CREATE TABLE new_table
("FROM_LIC" int, "FLOOR" timestamp, "INFEED" timestamp, "TROLLEY" timestamp, "OUTFEED" timestamp, "STAGING" varchar2(16))
INSERT ALL
INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
VALUES (4100002563, '04-Mar-2013 11:54:00 AM', '04-Mar-2013 11:55:00 AM', '04-Mar-2013 12:01:00 PM', '04-Mar-2013 12:01:00 PM', '03.04.2013 12:01')
INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
VALUES (4100003259, '04-Mar-2013 02:18:00 PM', '04-Mar-2013 02:19:00 PM', '04-Mar-2013 02:22:00 PM', '04-Mar-2013 02:23:00 PM', NULL)
INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
VALUES (4100003262, '04-Mar-2013 01:37:00 PM', '04-Mar-2013 01:39:00 PM', '04-Mar-2013 01:43:00 PM', '04-Mar-2013 01:44:00 PM', '03.04.2013 13:46')
SELECT * FROM dual
;What happened here is that for each instance of from_lic, the line yielded from
select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> in the new column called FLOOR.
And the following for the rest of the columns:
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> INFEED.
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> TROLLEY.
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> OUTFEED.
select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)The value for CREATE_DT ---> STAGING.
Originally I was thinking of a pivot for this, but there is possibly better ways to accomplish this.
I would like to have the data in the described format to make data mining easier.
The query will run on a table with >3M lines.
I hope this way of formulating the question is better, and more comprehensible.
Please do not hesitate to ask questions, and I'll do my best to answer.
I can test any suggested queries in the production database when necessary.
Edited by: 997749 on Apr 3, 2013 5:18 AM
Edited by: 997749 on Apr 3, 2013 6:20 AMHi,
what about something like this:
with trans as
SELECT 4100002563 from_lic, 'INN_MONO_05' to_location, TO_DATE('03.04.2013 11:54:21', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100002563 from_lic, 'INN_MONO_06_BANE_R' to_location, TO_DATE('03.04.2013 11:55:08', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100002563 from_lic, 'TROLLEY_19' to_location, TO_DATE('03.04.2013 12:01:06', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100002563 from_lic, 'STG010801' to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100002563 from_lic, 'UT_OPPLAST_5_2' to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100005037 from_lic, 'INN_MONO_05' to_location, TO_DATE('03.04.2013 11:18:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100005037 from_lic, 'INN_MONO_04_BANE_R' to_location, TO_DATE('03.04.2013 11:21:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100005037 from_lic, 'TROLLEY_16' to_location, TO_DATE('03.04.2013 11:25:43', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100005037 from_lic, 'UT_OPPLAST_3_4' to_location, TO_DATE('03.04.2013 11:26:37', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100005037 from_lic, 'STG010703' to_location, TO_DATE('03.04.2013 11:27:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100006658 from_lic, 'INN_MONO_08' to_location, TO_DATE('03.04.2013 11:00:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100006658 from_lic, 'INN_MONO_08_BANE_L' to_location, TO_DATE('03.04.2013 11:02:35', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100006658 from_lic, 'TROLLEY_22' to_location, TO_DATE('03.04.2013 11:07:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
SELECT 4100006658 from_lic, 'UT_OPPLAST_7_3' to_location, TO_DATE('03.04.2013 11:09:03', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL
, got_category AS
SELECT from_lic
, CASE
WHEN to_location like 'INN_MONO%BANE%'
THEN 'INFEED'
WHEN to_location like 'INN_MONO%'
THEN 'FLOOR'
WHEN to_location like 'TROLLEY%'
THEN 'TROLLEY'
WHEN to_location like 'STG' OR to_location like 'UT%GULV'
THEN 'STAGED'
WHEN to_location like 'UT_OPPLAST%'
THEN 'OUTFEED'
ELSE 'UNKNOWN'
END as cat
, create_dt
FROM trans
WHERE create_dt > (sysdate -10/24) -- adjusted for different timezone
SELECT * --FROM_LIC, lic_a, lic_b, lic_c, lic_d, lic_e
FROM got_category
PIVOT(MAX(create_dt) FOR cat IN('FLOOR' as floor,
'INFEED' as infeed,
'TROLLEY' as trolley,
'OUTFEED' as ooutfeed,
'STAGED' as staged));
FROM_LIC FLOOR INFEED TROLLEY OOUTFEED STAGED
4100002563 03-APR-2013 11:54:21 03-APR-2013 11:55:08 03-APR-2013 12:01:06 03-APR-2013 12:01:56
4100005037 03-APR-2013 11:18:31 03-APR-2013 11:21:54 03-APR-2013 11:25:43 03-APR-2013 11:26:37
4100006658 03-APR-2013 11:00:31 03-APR-2013 11:02:35 03-APR-2013 11:07:54 03-APR-2013 11:09:03 If not useful, please post your input data (CREATE TABLE and INSERT statements) and your expected output.
Regards.
Al -
Need serious help with JSP + JDBC/Database connection
Hey all,
I have to build an assignment using JSP pages. I am still pretty new and only learning through trial and error. I understand a bit now, and I have managed to get a bit done for it.
I am having the most trouble with a Login Screen. The requirements are that the a form in a webpage has Username/Number and Password, the user clicks Login, and thats about it. The values for the username/number and password NEED to come from the database and I cannot manage to do this. The thing I have done is basically hardcode the values into the SQL statement in the .jsp file. This works, but only for that one user.
I need it so it checks the username/number and password entered by the user, checks the database to see if they are in it, and if so, give access. I seriously am stuck and have no idea on what to do.
I dont even know if I have made these JSP pages correct for starters, I can send them out if someone is willing to look/help.
I have setup 3 other forms required for the assignment and they are reading data from the db and displaying within tables, I need to do this with non-hardcoded values aswell. Im pretty sure I need to use for example 'SELECT .... FROM .... WHERE username= +usrnm' (a variable instead of username="john" , this is hardcoded), I just CANNOT figure out how to go about it.
Its hard to explain through here so I hope I gave enough info. A friend of mine gave some psuedocode i should use to make it, it seems ok to follow, its just I do not know enough to do it. He suggested:
get the username and pass from the env vars
open the db
make an sql (eg SELECT user, pass FROM users WHERE user = envuser)
index.jsp points to login.jsp
login.jsp get the vars you put into index.jsp
opened the db
is the query returns nothing - then the user is wrong
OR if the passwords dont match
- redirect back to index.jsp
if it does match
- set up a session
- redirect to mainmenu.jsp
Anyway, thanks for any help you can give.
-AaronHi,
Try this... it may help you...
mainMenu.jsp
<html>
<body>
<form method="POST" action="login.jsp">
Username: <input type="text" name="cust_no">
<p>
Password: <input type="password" name="password">
<p>
<input type="submit" value="LOGIN">
</form>
</body>
</html>
login.jsp
<%@ page import="java.io.*, java.sql.*"%>
<html>
<body>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:rocky");
Statement statement = connection.createStatement();
String query = "SELECT cust_no, password FROM customers WHERE cust_no='";
query += request.getParameter("cust_no") + "' AND password='";
query += request.getParameter("password") + "';";
ResultSet resSum = statement.executeQuery(query);
if (request.getParameter("cust_no").equalsIgnoreCase(resSum.getString("cust_no") && request.getParameter("password").equalsIgnoreCase(resSum.getString("password"))
%>
<h2>You are logged in!</h2>
<%
else
%>
<h2>You better check your username and password!</h2>
<%
}catch (ClassNotFoundException cnfe){
System.err.println(cnfe);
}catch (SQLException ex ){
System.err.println( ex);
}catch (Exception er){
er.printStackTrace();
%>
</body>
</html>
I didn't check the code that I wrote. So you may have to fix some part of it. Also this may not be the best solution, but it will help you to understand the process easily.
The more efficient method is to check whether the result set returned from the database is null or not.... I hope you got the idea... Good luck!
Rajesh -
Hello, I have the following query that I'm running in Oracle SQL Developer 1.2.1
WITH group_by_4_column_results AS
(SELECT m_atschunk.employee AS employee,
SUM(CASE
WHEN
M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as rolloffs,
M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
FROM M_ATSCHUNK
group by employee, infractionDate, rolloffDaysCount
SELECT g4.*,
SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
FROM group_by_4_column_results g4
It will output the key elements of what I need. But where it sums up the 'total_rolloffs', I need to add that number back into the infractiondate column. Any help would be greatly appreciated.
CREATE TABLE M_ATSCHUNK
(EMPLOYEE varchar(50),
ROLLOFFDAYSCOUNT varchar(3),
INFRACTIONDATE date)
INSERT INTO M_ATSCHUNK (EMPLOYEE, ROLLINGOFFDAYSCOUNT, INFRACTIONDATE)
VALUES ('PHIL','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/02 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/03 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/04 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/05 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/02/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/03/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss')))Phil3061 wrote:
I need to add that number back into the infractiondate column.Well, in general you need to use UPDATE or better MERGE. Howebver, your data sample does not show any rollofs:
SQL> SELECT * FROM M_ATSCHUNK;
EMPLOYEE ROL INFRACTIO
PHIL YES 01-JAN-10
PHIL YES 02-JAN-10
PHIL YES 03-JAN-10
PHIL YES 04-JAN-10
PHIL YES 05-JAN-10
PHIL NO 01-FEB-10
PHIL NO 01-MAR-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI NO 01-JAN-10
EMPLOYEE ROL INFRACTIO
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
14 rows selected.
SQL> WITH group_by_4_column_results AS
2 (SELECT m_atschunk.employee AS employee,
3 SUM(CASE
4 WHEN
5 M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as
rolloffs,
6 M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
7 FROM M_ATSCHUNK
8 group by employee, infractionDate, rolloffDaysCount
9 )
10 SELECT g4.*,
11 SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
12 FROM group_by_4_column_results g4
13 /
EMPLOYEE ROLLOFFS INFRACTIO TOTAL_ROLLOFFS
NIKI 0 01-JAN-11 0
NIKI 0 01-JAN-11 0
PHIL 0 01-JAN-11 0
PHIL 0 02-JAN-11 0
PHIL 0 03-JAN-11 0
PHIL 0 04-JAN-11 0
PHIL 0 05-JAN-11 0
PHIL 0 01-FEB-11 0
PHIL 0 01-MAR-11 0
9 rows selected.
SQL> So adjust data sample and based on it tell us what are the expected results.
SY. -
Need help with query that can look data back please help.
hi guys i have a table like such
CREATE TABLE "FGL"
"FGL_GRNT_CODE" VARCHAR2(60),
"FGL_FUND_CODE" VARCHAR2(60),
"FGL_ACCT_CODE" VARCHAR2(60),
"FGL_ORGN_CODE" VARCHAR2(60),
"FGL_PROG_CODE" VARCHAR2(60),
"FGL_GRNT_YEAR" VARCHAR2(60),
"FGL_PERIOD" VARCHAR2(60),
"FGL_BUDGET" VARCHAR2(60)
)and i have a data like such
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
so im trying to write a query that basically does the following.
im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
so the expected outcome should be $700
240055 240055 7240 4730 02 10 14 200
240055 240055 7600 4730 02 10 14 100
240055 240055 7600 4730 02 11 1 400keep in mind that im not given a year just a period.
any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
finally broke down and put together this post
Edited by: mlov83 on Sep 14, 2011 8:48 PMFrank
wondering if you can help me modify this sql statement that you provided me with .
table values have been modified a bit.
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
the current period +(current period - greatest year 00)
hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
period 2 amount $ 600
period 0 amount $ 400 - period 2 amount of $600 = 200
600+200 = $800
if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
can you please help me out.
Miguel -
Need Help With Query Using Aggregation
If I have a table, defined like this:
CREATE TABLE range_test
range_id NUMBER(20) NOT NULL,
grade CHAR(1) NOT NULL,
lower_bound_of_range NUMBER(5,2) NOT NULL,
upper_bound_of_range NUMBER(5,2) NOT NULL,
received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
I want something like the following, but I know that this won't work right:
SELECT
grade,
lower_bounding_of_range,
upper_bounding_of_range,
max(received_date_time_stamp)
FROM
range_test GROUP BY received_date_time_stamp;
Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).Perhaps something along the lines of...
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from emp
3* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7782 CLARK 09-JUN-1981 00:00:00
10 7839 KING 17-NOV-1981 00:00:00
10 7934 MILLER 23-JAN-1982 00:00:00
20 7369 SMITH 17-DEC-1980 00:00:00
20 7566 JONES 02-APR-1981 00:00:00
20 7788 SCOTT 19-APR-1987 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
20 7902 FORD 03-DEC-1981 00:00:00
30 7499 ALLEN 20-FEB-1981 00:00:00
30 7521 WARD 22-FEB-1981 00:00:00
30 7654 MARTIN 28-SEP-1981 00:00:00
30 7698 BLAKE 01-MAY-1981 00:00:00
30 7844 TURNER 08-SEP-1981 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from (
3 select deptno, empno, ename, hiredate
4 ,row_number() over (partition by deptno order by hiredate desc) as rn
5 from emp
6 )
7 where rn = 1
8* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7934 MILLER 23-JAN-1982 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
SQL> -
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100I want the output to look like this:
ACCT_CODE CURRENT_YEAR(11) PRIOR_YEAR(10)
A123 100 50
A456 200 100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!
Edited by: user5737516 on Jun 29, 2011 6:48 AM
Edited by: user5737516 on Jun 29, 2011 6:50 AMuser5737516 wrote:
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100
I want the output to look like this:
ACCT_CODE CURRENT_YEAR PRIOR_YEAR
A123 100 50
A456 200 100
The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!what is prior year? -
Query off of Oracle using WinSql - Need help with query
I am trying to query off of Oracle using program WinSql.
I have a table(tticpr200110) that has the following sample data:
ITEM CODE T$AMNT
23500076 ACL .0049
23500076 APM 0
23500076 APO .0093
23500076 EXP .0001
23500076 RES .0072
and what I want it to look like is:
ITEM ACL APM APO EXP RES
23500076 0.0049 0 0.0093 0.0001 0.0072
(actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
Seems simple enough, but I don't know to put into the columns.
Any help would be GREATLY appreciated as soon as possible would be even better.My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
The first coloumn ITEM is the part number.
The second column CODE is 1 of 5 different cost codes
The third column is the cost for that code for that part.
ITEM CODE AMNT
23500076 ACL 0.0049
23500076 APM 0.0000
23500076 APO 0.0093
23500076 EXP 0.0001
23500076 RES 0.0072
I want to make a query that makes the data look like this:
ITEM ACL APM APO EXP RES
23500076 0.0049 0.0000 0.0093 0.0001 0.0072
(similar to a pivot table in excel or acess)
I hope this helps better.
Thanks! -
Need help with Query to determine Credit Memos and Invoices
Hi All
Thanks for all the help here.
I need a query to determine any credits or invoices issued within a given period.
OINV and ORIN with UNION ALL?
Please advise any help.
Thank you!Hi Daniel,
Please check below Query.
SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0 LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] = T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate] >=[%3] AND T0.[DocDate] <=[%4]
Hope this helps
Regards::::
Atul Chakraborty -
Hello all,
As a new PHP/SQL developer I have found great technical assistance from both this forum and from David Powers and his wonderful books. I am at a crucial point in my web development and although I believe I know which direction I need to go, I am still uncertain and so I appeal to you all for your help, especially David Powers.
The website I am building is one which will house many photo galleries. I was able to successfully modify the code provided in David Powers’ book ‘php Solutions’ so that I got the photo galleries constructed and working in the manner I desired.
That being said, a person browsing my website will be presented with a link to see the photo galleries. There will be five (5) categories in which the photos will be separated, all based on specific styles. Now that I have the galleries working, I need to know how to structure things so that I can create a page, like a TOC (table o’ contents) that shows all photo galleries by displaying a thumbnail image or two along with the description. Perhaps I’ll limit the TOC page to only show the latest 25 galleries, arranged with the most current always on top.
The way I have my galleries set up, I have a separate database for each one, containing the photo filenames and other relevant data. To build my TOC structure, should I have an overall database that contains each gallery database filename along with category? This is where I have no idea what I’m doing so if my question sounds vague, please understand I have no other idea how to ask.
The site will grow to the point of having hundreds, if not thousands of photo galleries. I simply want to know how to (organize them) or otherwise allow me to build a method to display them in a TOC page or pages.
I know this is a bit dodgy, but with some info and questions back from you, I feel confident that I should be able to get my point across.
Lastly, I am still developing this site locally, so I have no links to provide (though I feel that shouldn’t be necessary right now).
Many sincere thanks to you all in advance,
wordmanbregent,
I'm chewing this over in my head, reading up on DB's in 'phpSolutions' and I think that things are slowly materializing.
Here is the structure of the website that I have planned:
MAIN PAGE
User is presented with a link on the main page to select photo galleries (other links are also present). Clicking the link takes them to the Category Page.
CATEGORY PAGE
On this page, the User will then have 5 choices based on categories (photo style). CLicking any of these 5 links will take them to respective TOC pages.
TOC PAGE
On this page, the user is greeted with a vertical list of galleries or photosets; one to three thumbs on the left, a small block of descriptive text on the right (ideally containing date/time info to show how recent the gallery is). Newest galleries appear at the top. Eventually, when there are tens or hundreds of galleries in any given catrgory, I'll need to adopt a method for breaking up the qualntity in groups (we can pick 20 for example) that can be scrolled through using a small navbar. This will keep the TOC Pages from getting endlessly long and avoid endless scrolling. User selects a gallery on this page to view.
THUMBNAIL PAGE
On choosing a gallery, a thumbnail page is generated (I have this working already)
IMAGE PAGE
On selecting any thumbnail in the grid, the user is taken to the full-sized photo with a navbar and photo counter at the top. Navlinks allow forward and back, a link to the first image, a link to the last image and one link back to the thumbnail page. (I have this working already).
I provide this info in an effort to help understand the basic structure of my site. The description above is as close to a step-by-step illustration as possible.
Thank you!
Sincerely,
wordman -
[Oracle 8i] Help with query performance
The following query is running VERY slowly for me:
SELECT oord.part_nbr
, sopn.ord_nbr
, sopn.sub_ord_nbr
, sopn.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
, pact.activity_date
FROM PACT pact
, SOPN sopn
, OORD oord
WHERE pact.order_nbr = sopn.ord_nbr AND
pact.maj_seq_nbr = sopn.major_seq_nbr AND
sopn.sub_ord_nbr = pact.sub_order_nbr AND
sopn.ord_nbr = oord.ord_nbr AND
sopn.sub_ord_nbr = oord.sub_ord_nbr AND
pact.activity_date >= ? AND
sopn.rework_ind = 'N' AND
(oord.part_nbr, sopn.major_seq_nbr, sopn.wctr_id)
NOT IN (
SELECT rout.doc_nbr
, rout.major_seq_nbr
, rout.wctr_id
FROM ROUT rout
WHERE (rout.begn_eff_dt <=SYSDATE) AND
(rout.end_eff_dt >SYSDATE) AND
(rout.po_rework_ind ='N')
GROUP BY oord.part_nbr
, sopn.ord_nbr
, sopn.sub_ord_nbr
, sopn.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, pact.activity_dateI sent a request off to my IT department (specifically asking for the explain plan and tkprof, as described in the [main post on this topic|http://forums.oracle.com/forums/thread.jspa?threadID=501834] ), and they replied with a screen shot of the 'explain plan' the tool they use (Toad) provides.
!http://temp-sample.webs.com/explain_plan.jpg!
I don't know if anyone can help me based off this, since I know it's not really what the main post says to provide, but it's all I was given.
My IT department also made a few changes to my original query (see below) and told me it got rid of one of the full scans of the PACT table, but they aren't sure why it helped, and I have to say I'm suspect of any fixes where it's not understood why it helped.
SELECT oord.part_nbr
, sopn.ord_nbr
, sopn.sub_ord_nbr
, sopn.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
, pact.activity_date
FROM PACT pact
, SOPN sopn
, OORD oord
WHERE sopn.ord_nbr = pact.order_nbr AND
sopn.major_seq_nbr = pact.maj_seq_nbr AND
pact.sub_order_nbr = sopn.sub_ord_nbr AND
oord.ord_nbr = sopn.ord_nbr AND
oord.sub_ord_nbr = sopn.sub_ord_nbr AND
(pact.activity_date >= ?) AND
'N' = sopn.rework_ind AND
pact.order_nbr = oord.ord_nbr AND
oord.sub_ord_nbr = pact.sub_order_nbr AND
(oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) NOT IN
SELECT /*+ INDEX_JOIN(ROUT) */ rout.doc_nbr
, rout.major_seq_nbr
, rout.wctr_id
FROM ROUT rout
WHERE rout.begn_eff_dt <= SYSDATE AND
rout.end_eff_dt > SYSDATE AND
'N' = rout.po_rework_ind
GROUP BY oord.part_nbr
, sopn.ord_nbr
, sopn.sub_ord_nbr
, sopn.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, pact.activity_dateAny help on this would be appreciated... when I run this (right now) for 2-3 months of data, it takes a minimum of 3 hours to complete, and I'll eventually need to run this for up to a year's worth of data.Hi,
Well, let's see.
You get 156 rows returned using IN and 121 rows using exists.
You need identify the 'missing records' and conclude if that's correct or not, I'm not able to do that from remote, without knowing your data or system.
It would be helpful if we could see cost and cardinalities, you (or your IT dept.) can get them easily be running the queries from your SQL*Plus prompt.
Type
SET AUTOTRACE TRACEONLYbefore running the queries.
That gives you the explain plan and additional statistics (sorts in memory and sorts to disk).
Since you use a group by, and you're on 8i can you also post results of these queries:
select banner from v$version;
select name, value, isdefault from v$parameter where name like '%area%';Finally, does below query give you a different plan?
select oord.part_nbr
, oord.ord_nbr
, oord.sub_ord_nbr
, pact.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, sum(pact.act_dlrs_earned + pact.act_brdn_dls_earned + pact.tool_dlrs_earned + pact.act_fix_brdn_dls_ea)
, pact.activity_date
from oord oord
, pact pact
, sopn sopn
where oord.ord_nbr = pact.order_nbr
and oord.sub_ord_nbr = pact.sub_order_nbr
and oord.ord_nbr = sopn.ord_nbr
and oord.sub_ord_nbr = sopn.sub_ord_nbr
and sopn.major_seq_nbr = pact.maj_seq_nbr
and (pact.activity_date >= ?)
and 'N' = sopn.rework_ind
and (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) not in ( select rout.doc_nbr
, rout.major_seq_nbr
, rout.wctr_id
from rout rout
where rout.begn_eff_dt <= sysdate
and rout.end_eff_dt > sysdate
and 'N' = rout.po_rework_ind)
group by oord.part_nbr
, oord.ord_nbr
, oord.sub_ord_nbr
, pact.major_seq_nbr
, sopn.wctr_id
, sopn.oper_desc
, pact.activity_date -
Help with updating a database while in cfloop
Greetings. I'm having some difficulties in updating a
database using cfquery inside of a cfloop.
Background:
I've got a text file that I need to interpret, line for line,
and then update an existing database with information from that
text file. For example, the text file might say
jdoe~103 Anywhere St.~East Nowhere~New Jersey~05784~
asmith~8963 North St.~Crabapple Cove~Maine~01390~
(etc...you get the idea)
So, I use a CFFILE to read the file, and then calculate the
number of lines (records to be updated in the database) using
listlen / 5 (in this example). From there, I:
<cfloop index="record" from="1" to "#numberoflines#">
<cfloop index="field" from="1" to "5">
<cfset position = ((record - 1) * 5) + field>
<cfelseif field EQ 1>
<cfset form.username =
ListGetAt(newcontents,position,"~")>
<cfelseif field EQ 2>
<cfset form.street =
ListGetAt(newcontents,position,"~")>
(etc...through EQ 5)
</cfloop>
<cfquery name="updatedatabase"
datasource="clientlist">
UPDATE clients
SET
Street= '#form.street#',
(etc)
WHERE email = '#form.username#'
</cfquery>
</cfloop>
The problem I am having is that it updates the very first
record in the set of records to update, but then it does not update
any subsequent records.
Why?
Sorry if the code is crude. Is there a better way of doing
this? If so, great detail would be helpful :) Relatively new at
this.
-Brianquote:
Originally posted by:
Dan Bracuk
Updating a db from a file using cold fusion is generally
inefficient and should only be used as a last resort. If your db
has any bulk loading/updating utilities, consider using them. Maybe
you can use cold fusion to upload the file and ftp it to your db
server or something like that.
Better yet, that file has to come from somewhere. Is there a
way you can update your db instead of generating a file in the
first place?
The file starts as an output generated by a web user (an
administrator on the software) which creates a text file containing
email addresses, one per line. An external process which I have no
control over takes that file and generates another file containing
information about each of those e-mail addresses (last name, first
name, etc) one per line. I can't change that process. So, I'm left
with an external text file that I need to parse and then put into
the database...all through a web interface. The goal here is that
an administrator of the software, who does not have direct access
to the database, can (using cold fusion processing) update the
database with new information on each e-mail address without my
intervention.
-Brian
Maybe you are looking for
-
Sender File Adapter (1 Header only, Multiple Detail) withour keyfield ?
Hi, is that possible to read file with content converstion for this file structure below : 100,200,10-AUG-2010 ABC,500,100 DEF,400,200 GFD,400,200 Since every file only contain 1 headers there is no idicator header and detail. Please advise how to ac
-
Problem with trackpad - clicking by touch
Since upgraded to ML, trackpad clicks by touch every time I rest my fingers on it for more than 2 or 3 seconds. With Lion, I need to PRESS and physical click the trackpad. This is very very irritating since I need to move the fingers away from the tr
-
It is important to me to be able to find messages that I have sent TO a person as well as messages I have RECEIVED from that person. I used to be able to do that but now, for some unknown reason, whenever I do a search on an email address the only me
-
Update BP currency failed in DTW
Dear All, I tried to update BP currency by using DTW. I have the recordkey, BP code, currency code in the txt file. However, only 4 of them are done. Others are failed. I got an error message: cannot find this object in B1Application-defined or obje
-
Batch archiveing procedure issues
Hi I am trying to archive Material batches ...but i have structued in process i have followed below steps: i have maintained varient in mm74 t.code ... then click on start button ..click on immediately ..its become green ..then click on spool button