Query Help
Table1:
ou store point
LS LIB1 50
LS LIB1 200
LS LIB1 100
LS LIB1 79
I have to insert table1 to table2 by splitting into every 143point and assing serial number for every 143 from parameter.
in aboce example we can split 3 time 143 like below table2 sample.
Table2
ou store point serial_number
LS LIB1 50 101
LS LIB1 93 101
LS LIB1 107 102
LS LIB1 36 102
LS LIB1 64 103
LS LIB1 79 103
i tried below procedure its not working.
table may have any order like below.
Table1:
ou store point
LS LIB1 200
LS LIB1 50
LS LIB1 100
LS LIB1 79
then table2
ou store point serial_number
LS LIB1 143 101
LS LIB1 57 102
LS LIB1 50 102
LS LIB1 36 102
LS LIB1 64 103
LS LIB1 79 103
create or replace procedure assign_serial(from_num number,to_num number) is
bal number(10);
begin
bal := 0;
for c1 in(select * from table1)
loop
if c1.point <=143 then
if bal=0 then
bal=143-used;
insert int0 table2 values(c1.ou,c1.store,used);
elsif used > 0 then
used=used-bal;
insert int0 table2 values(c1.ou,c1.store,bal);
bal=0;
if used > 0 then
insert int0 table2 values(c1.ou,c1.store,used);
end if;
bal:=143-used;
end if;
end loop;
end;
How to split and assign serial number,please hELP.
.after giving serial num i have to change points in table1 to 0.The problem for SUm and split for every 143 is ,different OU and store is there.we have to know for which store points we earned serial number.
i hope this below logic little satisfy except assign cardnum,please........ check and currect the logic
LS LIB1 50
LS LIB1 200
LS LIB1 100
LS LIB1 79
--variable used and bal
for c1 in(select * from table1)
loop
used := c1.points;
if c1.point <=143 then
if bal=0 then
bal=143-used;
insert int0 table2 values(c1.ou,c1.store,used);
elsif used > 0 then
used=used-bal;
insert int0 table2 values(c1.ou,c1.store,bal);
bal=0;
if used > 0 then
insert int0 table2 values(c1.ou,c1.store,used);
end if;
bal:=143-used;
end if;
end loop;
Similar Messages
-
Query Help:
http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
The above was my previous posting, which was not clear..so Iam restating my problem as follows....
I have the following tables
Customer(custID, Name, Address)
Order(custID, OrderID, orderDate)
CreditCard(custID, creditCard#, creditCardType)
Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
Order:
100,A001,11/22/03
100,A002,11/24/03
100,A003,12/02/03
CreditCard:
100,42323232..., VISA
100,5234234...., MASTER
Now how can I get
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
data in minimum no. of records....
I think I have made my query clear..
now please help me guys...
thanks so much for your help.You are right.
But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
Can you please help me with the query
if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
With the following fields in my query result,
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
from Customer, Order, CreditCard tables
Thanks so much for your htlp -
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-( -
hii
i need a query help
i have two tables
the 1st table will look like this
associate id weekid no.of. hours
4000 810 40
4000 820 30
4000 830 60
4000 840 70
2nd table will look like this
associate id weekid no.of.hours
4000 810 40
4000 820 70
4000 830 130
4000 840 200
so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
for example
consider week id 830 and 840
in second table 830=130
840=200
when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
1 ---->>>> 840 - 830
=200 - 130
=70
in first table 840 has 70 hrs
like this it shud check with all records and it shud return only the records which are not equal
regards
srikanthThis..?
sql>select * from t1;
A_ID W_ID HRS
4000 810 40
4000 820 30
4000 830 60
4000 840 70
4000 850 80
sql>select * from t2;
A_ID W_ID HRS
4000 810 40
4000 820 70
4000 830 130
4000 840 200
4000 850 260
sql>
select a_id,w_id,hrs,sum_hrs
from(
select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
t2.hrs - nvl(lag(t2.hrs) over(order by t1.w_id),0) diff
from t1,t2
where t1.w_id = t2.w_id)
where diff != hrs;
A_ID W_ID HRS SUM_HRS
4000 850 80 260 -
Query help on Goods Receipt Query with AP Invoice
Looking for a little help on a query. I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice). I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start. SBO 2005 SP01. Any help would be great appreciated. Thanks
SELECT distinct 'GR',
D0.DocStatus,
D0.DocNum ,
D0.DocDate,
D0.DocDueDate,
D0.DocTotal,
'AP',
I0.DocStatus,
I0.DocNum ,
I0.DocDate,
I0.DocDueDate,
I0.DocTotal,
I0.PaidToDate
FROM
((OPDN D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
full outer join
(OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
WHERE
(D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry
FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))Hi Dalen ,
I believe it is because of the condition
(D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
Try changing
D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
Lets see what would be the result . Lets have some fun with troubleshooting
See what would be the difference in the result .
Thank you
Bishal -
Query help: query to return column that represents multiple rows
I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
I need a query to find all names that occur in both of two separate locations.
For example,
bob usa
bob mexico
dot mexico
dot europe
hal usa
hal europe
sal usa
sal mexico
The query in question, if given the locations usa and mexico, would return bob and sal.
Thanks for any help or advice,
-=beekyHow about this?
SELECT NAME
FROM <LOCATIONS_TABLE>
WHERE LOCATION IN ('usa','mexico')
GROUP BY NAME
HAVING COUNT(DISTINCT LOCATION) >= 2Results:
SQL> WITH person_locations AS
2 (
3 SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
4 SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
5 SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
6 SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
7 SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
8 SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
9 SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
10 SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
11 )
12 SELECT NAME
13 FROM person_locations
14 WHERE LOCATION IN ('USA','Mexico')
15 GROUP BY NAME
16 HAVING COUNT(DISTINCT LOCATION) >= 2
17 /
NAM
bob
salHTH!
Edited by: Centinul on Oct 15, 2009 2:25 PM
Added sample results. -
QUERY HELP!!! trying to create a query
i'm creating a summary report
i have a table with sale dates
for example i have a table tab_1 and column saleDate as
saleDat
1923
1936
1945
2003
2005
saleDate contains years and there are some missing years where no sale
was made
My report has to display years starting from earliest year
so i have to create a query that starts with 1923
but the problem is that I have to have years that are not in table.
for example i have to display years 1924 which is not in table
so the part of report has to look like
1923 blah blah summary.........
1924 "
1925
1926
2005
2006
upto current year (2006 may not be in the table, but i have to display)
i just need to know the query that can query all the years starting from
the ealiest saleDate to current year
thanks in advancePlease write the query in the following form:
SELECT a.year, --- place other columns from your table.
FROM (SELECT (:start_num + rownum) year
FROM all_tab_columns
WHERE :start_num + rownum <= :end_num) a,
tab_1 b
WHERE a.year = b.saleDat(+);
Note:
1) if your start year and end year are 1923 and 2006. Then input as below:
:start_num = 1922
:end_num = 2006
2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
Hope this helps.
- Saumen. -
Pulling open invoices, and paid invoices with details (Query Help).
Hello All,
I am sure I messed something up in my joins. I am looking to pull a report of all invoices OINV for a month, then list details of any payment (if it is paid) next to it from RCT2. It is giving me a list of all of the paid invoices, but even though I have a LEFT JOIN it is not listing any of the invoices without payments.
This is where I am now from the report wizard in Crystal.
SELECT "OINV"."DocNum", "OINV"."SlpCode", "OINV"."CardCode", "OINV"."DocTotal", "OINV"."U_Commission", "OSLP"."SlpName", "RCT2"."DcntSum", "ORCT"."TaxDate", "OINV"."DocEntry", "OINV"."TotalExpns", "OINV"."CANCELED", "ORCT"."Canceled", "ORCT"."DocNum", "RCT2"."InvType"
FROM ("DBName"."dbo"."OINV" "OINV" LEFT OUTER JOIN "DBName"."dbo"."OSLP" "OSLP" ON "OINV"."SlpCode"="OSLP"."SlpCode")
INNER JOIN ("DBName"."dbo"."ORCT" "ORCT" INNER JOIN "DBName"."dbo"."RCT2" "RCT2" ON "ORCT"."DocNum"="RCT2"."DocNum")
ON "OINV"."DocEntry"="RCT2"."DocEntry"
WHERE "OINV"."CANCELED"='N' AND "ORCT"."Canceled"='N' AND "RCT2"."InvType"<=N'14'
ORDER BY "OINV"."SlpCode", "ORCT"."DocNum", "ORCT"."TaxDate"
Thank you in advance for any help you can give me.Hello Kiran,
I thought about that, but my purposes for running the report is to determine commission based on the date that the invoice was paid, I need the TaxDate in ORCT as it relates to the payment in RCT2.
Removing the ORCT.cancelled condition and the RCT2.invtype conditions now pulls all of the invoices, paid and unpaid. I know now I cant have them in my query, when the record does not exist in ORCT it doesnt have a value for cancelled, and when there is no record in RCT2 there is no invtype, and is filtered.
Maybe I can say where ORCT.Canelled = 'N' OR ORCT.Cancelled = NULL, but I dont know if that would work. -
Query Help for reporting on last receipt qty
SBO Version: 8.82 PL11
Hello Forum,
I am looking for some help devising a command behind a crystal report. We are hoping to achieve the last receipt quantity. To arrive at this we would like it to get the last GRPO for an item and total the quantity on that particular GRPO. In addition to this, we want to consider all the lines on the document and SUM them.
At present, the query I have is as follows:
Select SUM(c0.Quantity) from PDN1 c0 WHERE c0.ItemCode = T1.ItemCode AND Shipdate = (select Max(ShipDate) from PDN1 C0 INNER JOIN OPDN c1 ON c0.DocEntry = c1.DocEntry where C0.Itemcode =T1.ItemCode AND c1.DocStatus <> 'C'))
Any assistance would be greatly received.
Thanks
SarahHi Sarah,
Please repost to the SAP Business One Application space.
-Abhilash -
SQL Query help ( On connect By level clause)
Hi all,
I have this query developed with data in with clause.
With dat As
select '@AAA @SSS @DDD' col1 from dual union all
select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual
Select regexp_substr( col1 , '[^@][A-Z]+',1,level) Show from dat
connect by level <= regexp_count(col1, '@');Current output :-
SHOW
AAA
SSS
DDD
RRR
ZZA
TTT
RRR
ZZA
XXX
DDD
RRR
SHOW
ZZA
TTT
RRR
ZZA
. . .1st row comes fine, But next row data is getting duplicated. And total record count = 30. I tried with some but didn't work.
Expected output :-
SHOW
AAA
SSS
DDD
ZZZ
XXX
TTT
RRR
ZZAI need some change on my query and I am not able to find that. So anybody can add on that or can also provide some different solution too.
Thanks!
AshutoshHi,
When you use something like "CONNECT BY LEVEL <= x", then at least one of the following must be true:
(a) the table has no more than 1 row
(b) there are other conditions in the CONNECT BY clause, or
(c) you know what you are doing.
To help see why, run this query
SELECT SYS_CONNECT_BY_PATH (dname, '/') AS path
, LEVEL
FROM scott.dept
CONNECT BY LEVEL <= 3
;and study the results:
PATH LEVEL
/ACCOUNTING 1
/ACCOUNTING/ACCOUNTING 2
/ACCOUNTING/ACCOUNTING/ACCOUNTING 3
/ACCOUNTING/ACCOUNTING/RESEARCH 3
/ACCOUNTING/ACCOUNTING/SALES 3
/ACCOUNTING/ACCOUNTING/OPERATIONS 3
/ACCOUNTING/RESEARCH 2
/ACCOUNTING/RESEARCH/ACCOUNTING 3
/ACCOUNTING/RESEARCH/RESEARCH 3
/ACCOUNTING/RESEARCH/SALES 3
/ACCOUNTING/RESEARCH/OPERATIONS 3
/ACCOUNTING/SALES 2
/ACCOUNTING/SALES/ACCOUNTING 3
84 rows selected. -
Query Help required to Connect JDT1 with OINV tables
Dear Experts,
I have the following query which gives me the customer ageing report. I want some addtional fields from the OINV table and the document numbering table like Document Series Name, AR Invoice document Number,AR invoice remarks, BP Projects Number ( filled in accounting tab in BP projects) and in the query in Reference 1 column its giving the Invoice Numbers as posted in the Journal but for manual Journal Entries it not giving the Journal Number which I also want to be shown in Ref 1 or a seperat field.
The Query is as under :
select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
case JDT1.transtype
when '13' then 'INV'
when '14' then 'AR CN'
when '24' then 'INCOMING'
else 'Other'
end 'Type',
Ref1,
fccurrency 'BP Currency',
CONVERT(VARCHAR(10), refdate, 103)'Posting Date' ,
CONVERT(VARCHAR(10), duedate, 103) 'Due Date',
CONVERT(VARCHAR(10), taxdate, 103) 'Doc Date' ,
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 < 31
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "0-30 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 30
and (datediff(dd,refdate,current_timestamp))+1< 61)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "31 to 60 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 60
and (datediff(dd,refdate,current_timestamp))+1< 91)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "61 to 90 days",
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 > 90
then
case
when syscred= 0 then sysdeb
when sysdeb= 0 then syscred * - 1
end
end "90 + days"
from JDT1,OCRD where JDT1.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
ORDER BY OCRD.CARDCODE, taxdate
Would appreciate if you can help me to get a solution in it.
Regards,
KamleshDear Gordon,
While executing the followings modified query it giving an error of
Incorrect Syntax near the keyword 'to' and incorrect Syntax near 'Series'
the query is as under :
{select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
case l.transtype
when '13' then 'INV'
when '14' then 'AR CN'
when '24' then 'INCOMING'
else 'Other'
end 'Type',
j.BaseRef'Trans #',
case l.transtype
when '13' then
(Select Comments from OINV where OINV.Transid=j.Transid)
else '-'
end 'Inv.Rem.',
(Select SeriesName From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
to
(Select Isnull(SeriesName, 'Manual') From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
l.Ref1,
fccurrency 'BP Currency',
CONVERT(VARCHAR(10), l.refdate, 103)'Posting Date' ,
CONVERT(VARCHAR(10), l.duedate, 103) 'Due Date',
CONVERT(VARCHAR(10), l.taxdate, 103) 'Doc Date' ,
CASE
when (DATEDIFF(dd,l.refdate,current_timestamp))+1 < 31
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "0-30 days",
case when ((datediff(dd,l.refdate,current_timestamp))+1 > 30
and (datediff(dd,l.refdate,current_timestamp))+1< 61)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "31 to 60 days",
case when ((datediff(dd,l.refdate,current_timestamp))+1 > 60
and (datediff(dd,l.refdate,current_timestamp))+1< 91)
then
case
when syscred <> 0 then syscred * - 1
else sysdeb
end
end "61 to 90 days",
CASE
when (DATEDIFF(dd,l.refdate,current_timestamp))+1 > 90
then
case
when syscred= 0 then sysdeb
when sysdeb= 0 then syscred * - 1
end
end "90 + days"
from JDT1 l
Inner Join OJDT j On j.TransId=l.TransId
,OCRD where l.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
ORDER BY OCRD.CARDCODE, l.taxdate}
Regards,
Kamlesh -
Hi ,
Please help me on this…
Select * from EMP where Emp_Type in (1, 2 ) order by Emp_Type;
the above query gives me the result like this
Emp_Id Name Emp_Type
100 asas 1
101 dsds 1
122 gfgf 1
154 ytytyt 1
125 uyuy 1
153 reree 2
154 ytytt 2
600 trtrtr 2
700 gfghf 2
If I pass the Start with num 2 and give 3 as number of records to be displayed. I need to retrieve only the following rows..
Emp_Id Name Emp_Type
101 dsds 1
122 gfgf 1
154 ytytyt 1
154 ytytt 2
600 trtrtr 2
700 gfghf 2
If the Emp_Type was only one ie,
Select * from EMP where Emp_Type in (1) order by Emp_Type;
I know I can get it done by using TOP-N query method
select * from
(Select rownum RWnum ,A.* From
(Select * from EMP where Emp_Type in (1) order by Emp_Type) A
where rownum<=4)
where RWnum>=2;
but I am stuck up with doing for multiple Emp_Type..
here the Emp_Type could be more than two values…
Regards
Ben NarendranHi muthukumar S,dnikiforv,Vsugur
Thanks a lot for the analytical function ROW_NUMBER().
But still have some concern about the query you have given..
Let me first run the inner query.
SQL>
SQL > Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
EMP e where Emp_Type in (1, 2 ) order by Emp_Type;
EMP_ID NAME EMP_TYPE RNO
154 aaa 1 1
101 dsds 1 2
122 gfgf 1 3
125 aaa 1 4
100 asas 1 5
700 gfghf 2 1
600 trtrtr 2 2
153 reree 2 3
If I give the range from 2 and 3 am suppose to get the following rows.
EMP_ID NAME EMP_TYPE RNO
101 dsds 1 2
122 gfgf 1 3
600 trtrtr 2 2
153 reree 2 3
when I run the query you sent am getting the following result..
SQL > select * from
(Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
EMP e where Emp_Type in (1, 2 ) order by Emp_Type)
where rno between 2 and 3;
EMP_ID NAME EMP_TYPE RNO
101 dsds 1 2
154 aaa 1 3
600 trtrtr 2 2
700 gfghf 2 3
Here the company id 700 is not suppose to come, instead I have to get 153.
So I made some changes in the view and , wrote it like this
SQL> select * from
(select rno Rwnum,Outer_Qry.* from
(select Real_Qry.*,row_number() over(partition by emp_type order by emp_type)rno
from
(select emp_id,name,emp_type from emp where emp_type in (1,2) order by emp_type)Real_Qry)Outer_Qry
where rno <=3)
where Rwnum >=2;
RWNUM EMP_ID NAME EMP_TYPE RNO
2 101 dsds 1 2
3 122 gfgf 1 3
2 600 trtrtr 2 2
3 153 reree 2 3
I guess now am getting the correct result..
Please correct me if I am wrong, and please let me know if I have to make any modification on it..
Thanks and regards
Ben -
Hi... having problems with a query. Any assistance would be
much appreciated.
Two queries with identical columns: Villages_Query_1 and Villages_Query_2.
Both have these columns: Village_ID, Village_Name, Player_ID.
I need to find all records in Villages_Query_2 where the Village_ID's match but the Player_ID's have changed.
Example Village_Query_1
Village_ID
Village_Name
Player_ID
1
Houston
1
2
Dallas
2
3
Chicago
3
Example Village_Query_2
Village_ID
Village_Name
Player_ID
1
Houston
1
2
Phoenix
4
3
Chicago
3
4
New York
5
In this case, Village_ID = 2, has changed names (Dallas to Phoenix) and the Player_ID has changed (2 to 4). In addition, a new record was added.
The eventual output I need is to be able to report the following:
Player 2 village "Dallas" was taken by Player 4 and renamed "Phoenix".
New York is a new village owned by Player 5.
How the heck do I do this?? I have been trying query after query... reading about query of queries and JOINS and and and... I am now completely confused.
Help appreciated.
MarkWell... firstly... you do not use MS Access for that volume of data. Plain and simple. MS Access is for DBs like "My CD collection". It's a desktop application, and is not intended to be used other than as a desktop application.
Part of the reason for it not being appropriate for the job is that it can't do things like bulk loading data, which is kinda what you're wanting to do here. That aside, it's a single-user file-based DB which is simply not designed to work as the back-end for a web application (or any sort of serious application).
Anyway, I would approach this by putting all the data from the CSV files into the DB as is. Then on the DB run a query which gets all your changes. You're really going to struggle with the suggestions here to use valueList() to generate a list that is then used for a NOT IN(#list here#), because you're likely to have a mighty long list there. Even proper DBs like Oracle only allow 2000 entries in a list like that (SQL Server is about the same, from memory), so I doubt QoQ will allow even that. The reason the DBs put limits on these things is that doing a WHERE IN (#list#) is a really poorly-performing process.
If you've got all your data in the DB, then your query becomes pretty easy, and I'm sure even Access could cope with it. it'd be something like this:
SELECT VB.village_id, VB.village_name AS village_old_name, VB.player_id AS player_old_id,
VU.village_id AS village_new_id, VU.village_name AS village_new_name, VU.player_id as player_new_id
FROM villages_base VB
RIGHT OUTER JOIN villages_updates VU
ON VB.village_id = VU.village_id
WHERE VB.village_name != VU.village_name
(that's untested and I only gave it about 1min thought before typing it in, so don't quote me on that!)
Where VILLAGE_BASE is your original data, and VILLAGE_UPDATES is the data that indicates the changes. I'm kinda guessing that this is the sort of thing you want. Note: the "new" villages will be the ones which have NULLs for the village_id, village_old_name and player_old_id.
Getting all the data into the DB is going to be a matter of looping over the CSV file and doing an INSERT for each row. And that will take as long as it takes, so you might need to get some control over your request timeouts. However doing these inserts will take less time than all the QoQ logic suggested before, so you might be OK. And the query should be quick.
What happens to the data once the report is written? Does the "updated" data become the "live" data? If so, after you run your report you're gonna want to do something like a TRUNCATE on villages_base, and INSERT all the records from villages_update into it (then TRUNCATE villages_update, ready for the next time you need to run this process). Although don't take my word for it here, as I'm guessing your requirement here ;-)
Adam -
Hi
I need help in writing a sql query for the data given below
Market Description Revenue
LARGE CORPORATE 0.0
LARGE CORPORATE 0.0
OTHERS 0.0
OTHERS 1.98
LARGE CORPORATE 5.1299999999999999
LARGE CORPORATE 6.8500000000000005
LARGE CORPORATE 10.98
LARGE CORPORATE 16.490000000000002
LARGE CORPORATE 21.129999999999999
LARGE CORPORATE 28.66
LARGE CORPORATE 38.579999999999998
OTHERS 68.420000000000002
OTHERS 87.590000000000003
LARGE CORPORATE 90.040000000000006
LARGE CORPORATE 511.94
LARGE CORPORATE 625.01999999999998
LARGE CORPORATE 662.75999999999999
LARGE CORPORATE 700.68000000000006
LARGE CORPORATE 2898.6799999999998
LARGE CORPORATE 3273.96
OTHERS 3285.4400000000001
LARGE CORPORATE 3580.0799999999999
LARGE CORPORATE 4089.1900000000001
LARGE CORPORATE 4373.5200000000004
LARGE CORPORATE 16207.550000000001
LARGE CORPORATE 19862.740000000002
LARGE CORPORATE 33186.150000000001
LARGE CORPORATE 107642.79000000001
The output of query should be in the following format
Market Description 1st 10%(revenue) 2nd 10%(revenue) 3rd 10%(revenue) 4th 10%(revenue) 5th 10%(revenue) rest 50%(revenue)
Would appreciate any help on this query.Hi,
What does 1st 10%, 2nd 10% etc. mean?
Is it 0-10%, 11-20%, 21-30%....
If so, combination of floor,decode and division should help to
achieve the result.
For example for the followint table,
NAME SALE
SALES_GROUP1 .2
SALES_GROUP1 1
SALES_GROUP1 9
SALES_GROUP2 2.1
SALES_GROUP2 12.2
SALES_GROUP2 19.9
SALES_GROUP3 22.2
write,
select name,decode(floor(sale/10),0,sale,null) "1st10%",
decode(floor(sale/10),1,sale,null)"11to20%",
decode(floor(sale/10),2,sale,null) "21to30%"
from revenue;
I mean, using floor and division, your rounding all values b/w 0 to 10 as 0
Similarly, 11 to 20 has be rounded to 1 etc...then apply decode function it
to achive the result.
I hope this helps.
Regards,
Suresh
8i OCP. -
Query Help with Parent, Child, Child's Child
Hi all,
Need some help with a query. I'm trying to create a stored procedure that is sort of like a Customer, Order, Order, Details. In my situation the tables are different but nevertheless, I want to grab all the fields from the Parent, Child,
and Childs' Child, where the Parent.ParentID = @Parameter. I tried this:
CREATE PROCEDURE [dbo].[spGetCompleteProjectXML]
@ProjectID int = 0
AS
SELECT *,
(SELECT *,
(SELECT *
FROM PageControls
WHERE (PageControls.ProjectPageID = ProjectPages.ProjectPageID))
FROM ProjectPages
WHERE (ProjectPages.ProjectID = @ProjectID))
FROM Projects
WHERE (ProjectID = @ProjectID)
FOR XML AUTO, ELEMENTS
RETURN 0
I think I'm close, but it was my best effort. Could someone help?
thanks in advanceHi TPolo,
Regarding your description, are you looking for a sample like below?
CREATE TABLE customer(customerID INT, name VARCHAR(99))
INSERT INTO customer VALUES(1,'Eric')
INSERT INTO customer VALUES(2,'Nelson')
CREATE TABLE orders(orderID INT,customerID INT)
INSERT INTO orders VALUES(1,1);
INSERT INTO orders VALUES(2,1)
INSERT INTO orders VALUES(3,2)
INSERT INTO orders VALUES(4,2)
CREATE TABLE orderDetails(orderID INT,item VARCHAR(99))
INSERT INTO orderDetails VALUES(1,'APPLE1')
INSERT INTO orderDetails VALUES(1,'BANANA1')
INSERT INTO orderDetails VALUES(2,'APPLE2')
INSERT INTO orderDetails VALUES(2,'BANANA2')
INSERT INTO orderDetails VALUES(3,'APPLE3')
INSERT INTO orderDetails VALUES(3,'BANANA3')
INSERT INTO orderDetails VALUES(4,'APPLE4')
INSERT INTO orderDetails VALUES(4,'BANANA5')
SELECT customer.customerID,customer.name,
(SELECT orderId,
SELECT item FROM orderDetails WHERE orderID=orders.orderID FOR XML AUTO,TYPE,ELEMENTS
FROM orders Where customerID=customer.customerID FOR XML AUTO,TYPE,ELEMENTS)
FROM customer WHERE customerID=1
FOR XML AUTO,ELEMENTS
DROP TABLE customer,orderDetails,orders
If you have any feedback on our support, please click
here.
Eric Zhang
TechNet Community Support -
Hi
The following Query will show me catalogue IDs and Descriptions of all the hired outfits
for each Branch, with the revenue generated in descending order....
SELECT Members_Order.Catalogue_ID, Item.Item_Description, Item.Colour Orders.Branch_ID, Item.Hire_Charge, Members_Order.Number_of_Days, (Hire_Charge*Number_of_Days) AS Total
From Members_Order, Item, Orders
WHERE Members_Order.Item_ID = Item.Item_ID
AND Members_Order.Order_ID = Orders.Order_ID
ORDER BY Total DESC;What i want to do now is to create a query to show the details of the outfits, which are the same colour as the outfit which has generated the most revenue. I'm guessing this will involve an embedded select, using the same basis of the query above, but i'm unsure as to what should go with the embedded select?
I have the following so far, could anyone help to finish it off or point me the the right direction....?
SELECT Members_Order.Catalogue_ID, Item.Item_Description, Item.Colour, Item.Hire_Charge, Members_Order.Number_of_Days, (Hire_Charge*Number_of_Days) AS Total
From Members_Order, Item, Orders
WHERE Members_Order.Item_ID = Item.Item_ID
AND Colour = (SELECT Colour FROM Item WHERE
;Edited by: user10945931 on 15-Apr-2009 19:50Hello,
You can add count(*) and group by clause and using WITH clause. If you can post your table structure and some sample data that will be easier for us to help you out and if you like the challlegne and want to do it on your own then run start with above options. Also when you post code and output enclose them between \ to preseve formatting.
\your code or output goes here
\Regards
Maybe you are looking for
-
Availability at Storage Location Level
Dear All, While creating a sales order system is checking the material stock at the plant level it is including the stock in all the storage location we have several storage locations in the plant Hence i want to restrict the availablity to be done
-
Hi there, I created a datamodel and have applied a condition to it. When I execute the interface the invalid records are captured in the E$ table but all the other valid records do not appear on the target table. I couldn't able to find the reason fo
-
I have a Linksys cable modem and a Airport Extreme. When I go the the Gibson Research Corp,www.grc.com,and test my firewall, all I get is 6 ports that are stealth(green) and the rest are closed(blue).I am using McAfee's virus and firewall. I disable
-
How to Create code for HR operation
Hi Experts , i'm new in HR ABAP , i would like to know how to create HR operation , i need example code to create operation from scratch. Thanks Ahmed Saad Moderator Message: Please search for available information or take a classroom training on t
-
We get wrong settlements for a rebate type: 1. The system does not ask for an assignment. 2. the related accounting document does contain a posting on the customer number when it should be the GL Code. I already checked the Agreement type, and there