Kind of sequential query
Hello folks,
my requirement is: Given a number N (let's say 7 for this example) generate a query with following output:
SELECT A,B FROM some_query
A B
1 7
1 7
1 7
1 7
1 7
1 7
1 7
2 6
2 6
2 6
2 6
2 6
2 6
3 5
3 5
3 5
3 5
3 5
4 4
4 4
4 4
4 4
5 3
5 3
5 3
6 2
6 2
7 1
28 rows selected.Any ideas?
SQL> SELECT t3.i, t3.k, t3.j
2 FROM (SELECT t1.i, t1.k, t2.j, trunc((rownum - 1) / 7) + 1 d, rownum r
3 FROM (SELECT LEVEL i, 8 - LEVEL k FROM dual CONNECT BY LEVEL < 8) t1
4 ,(SELECT LEVEL j FROM dual CONNECT BY LEVEL < 8) t2) t3
5 WHERE t3.i + t3.r <= (7 * t3.d) + 1;
I K J
1 7 1
1 7 2
1 7 3
1 7 4
1 7 5
1 7 6
1 7 7
2 6 1
2 6 2
2 6 3
2 6 4
2 6 5
2 6 6
3 5 1
3 5 2
3 5 3
3 5 4
3 5 5
4 4 1
4 4 2
4 4 3
4 4 4
5 3 1
5 3 2
5 3 3
6 2 1
6 2 2
7 1 1
28 rows selected
SQL>
SELECT t3.i, t3.k, t3.j
FROM (SELECT t1.i, t1.k, t2.j, trunc((rownum - 1) / :base_number) + 1 d, rownum r
FROM (SELECT LEVEL i, :base_number + 1 - LEVEL k FROM dual CONNECT BY LEVEL < :base_number + 1) t1
,(SELECT LEVEL j FROM dual CONNECT BY LEVEL < :base_number + 1) t2) t3
WHERE t3.i + t3.r <= ( :base_number * t3.d) + 1;
Similar Messages
-
The following fields are to be taken from the tables as mentioned below:
Meter Reading Unit (MRU) (EANLH-ABLEINH)
MRU Description (TE422-TERMTEXT)
Meter Reading Center (TE422-ABL_Z)
Meter Reading Center Description (TE426T-TEXT40)
End Of Meter Reading Period (TE425-TERMERST)
Main Meter Reading Unit (TE422-ZUSMIT)
Number Of Installations Allocated (EANLH-ANLAGE)
These values as shown has to taken from the 4 tables
a. EANLH
b. TE422
c. TE426T
d. TE425
The query which I have written is
SELECT AABLEINH COUNT (AANLAGE) BTERMTEXT BABL_Z BZUSMIT CTEXT40 D~TERMERST
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ( ( (EANLH AS A INNER JOIN TE422 AS B ON AABLEINH = BTERMSCHL )
INNER JOIN TE426 AS C ON CABL_Z = BABL_Z )
INNER JOIN TE425 AS D ON DABLEINH = AABLEINH)
WHERE A~ABLEINH = 'input MRU' AND
SY-DATUM > A~AB AND
SY-DATUM < A~BIS
GROUP BY A ~ ABLEINH
Is it correct ??? If not, kindly modify.
Thx..Hi,
There is no restriction in using the Joins as the above reply. U can join 6 and more tables also. I have done teh same.
See this sample code
TABLES: SCUSTOM, SBOOK.
DATA: COUNT TYPE I.
SELECT SCUSTOM~NAME SCUSTOM~POSTCODE SCUSTOM~CITY
<b>COUNT( DISTINCT</b> SBOOK~LOCCURAM )
INTO (SCUSTOM-NAME, SCUSTOM-POSTCODE,
SCUSTOM-CITY, COUNT)
FROM SCUSTOM INNER JOIN SBOOK
ON SCUSTOM~ID = SBOOK~CUSTOMID
WHERE SBOOK~FLDATE BETWEEN '19950101'
AND '19951231' AND
SBOOK~CARRID = 'LH ' AND
SBOOK~CONNID = '0400'
<b>GROUP BY</b> SCUSTOM~NAME
SCUSTOM~POSTCODE SCUSTOM~CITY
<b>ORDER BY</b> SCUSTOM~NAME.
WRITE: / SCUSTOM-NAME,
SCUSTOM-POSTCODE,
SCUSTOM-CITY, COUNT.
ENDSELECT.
Message was edited by: Judith Jessie Selvi -
Query Help (Kind of Analytical query)
Hi,
I have a requirement in which i want to get the following output. I have taken DEPT & EMP as the example tables.
DEPT EMPLOYEES
10 1,2,3,4,5,6
20 7,8,9,10
30 11,12,13,14
Your help will be highly appreciated.
Regards,
Sunil.Hi Gabe,
Thanks for the quick reply. I checked the asktom site but here he has used PLSQL block to get the output.
Is it possible to get this output using a single SQL statement.
Thanks for the help.
Regards,
Sunil. -
Sequential read in sm66 - Database size 550GB - system slow for users
Hello,
Currently when we use any standard transactions or custom program, it is going to sequential read in sm66.
We are getting slowness in system due to this issue for users.
Sm66 log:
sapXX01_XXX_00 0 DIA 12873 Running Yes 6 XIRFC ZCL_WM_S Sequential Read MARD
sapXX01_XXX_00 20 BTC 16155 Running Yes 15 Zuser1 ZCL_SD_D Sequential Read LTAP
sapXX01_XXX_00 29 SPO 12018 Running Yes 12 Zuser1 print 35
sapXX01_XXX_00 30 SPO 12037 Running Yes 12 Zuser1 print 35
sapXX01_XXX_00 31 SPO 12041 Running Yes 12 SAPSYS querying
sapXX02_XXX_02 3 DIA 15098 Running Yes 714 Zuser2 ZCL_IM_B
sapXX02_XXX_02 4 DIA 8158 Running Yes 38 Zuser2 RWRPLPRO Sequential Read WRPL
sapXX02_XXX_02 6 DIA 8160 Running Yes 555 Zuser3 ZCL_IM_B
sapXX03_XXX_03 0 DIA 1969 Running Yes 2390 Zuser5 SAPLFAGL Sequential Read BSIS
sapXX03_XXX_04 0 BTC 10811 Running Yes 209 Zuser6 ZCL_SD_D Sequential Read LTA
Database: Maxdb
OS: Linux
I understand that if you create Index on these table ( whichever it shows as sequential read ), it will improve the report performance.
Most of the time, system process shows that sequential read on VBAP, VKPA (sales tables), purchase tables, Finance tables and etc.
If sm66 shows as sequential read for few table, that means that corresponding user will get slowness on getting report/transaction output. I agree on that.
Is there any reason other user will get slowness ie if i run Va03 transaction, WE02 transaction which is not relevant to sm66 process over view.
I appreciate, if you give some recommendations reg. this performance improvement and to avoid this kind of sequential read.
I posted the Same question in DB forum also.
I want to get some more idea from this forum also. That is reason, i posted here again.
Thanks
PrabaHi Volker,
Thanks for your reply.
We have three application server instance ie 00, 02, 03, -
04 (enque server)
1) This parameter value on 00 instance ie : rdisp/wp_no_spo - Number of spool work processes
Dflt value - 0
ProfileVa - 1
Current value - 1
Minimum - Nothing
Maximum - 100
2) his parameter value on 02 instance ie : rdisp/wp_no_spo - Number of spool work processes
Dflt value - 0
ProfileVa - 1
Current value - 1
Minimum - Nothing
Maximum - 100
3) his parameter value on 03 instance ie : rdisp/wp_no_spo - Number of spool work processes
Dflt value - 0
ProfileVa - 1
Current value - 1
Minimum - Nothing
Maximum - 100 -
Out standing MIS Report query problem.
Hi,
We designed MIS Report for outstanding mis through Crystal report.here we are facing probleme.ex:AR invoice raised on 01 Jan 09 bill amount 1000 and for this client is received full amount against that bill on 04 march09.in this report we provided parameters for from date and to date. When user selected in parameter from date 010109 to 050309 it will show pending amount is 0.but users are asking if they select from date upto 030309 means it will show pending amount should be show 1000.in this query we are retrieving based on document status when open. How we can show report for this requirements. Please guide me.if we give docstatus='O' or docstatus= 'C' it's showing but pending amount =Bill amount - paid amount here it's showing 0 i think here also we need to pass incoming payment docdate.how wen do please guide me.
below this is the query.
set @FromYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate)-1 else Year(@ToDate) end
set @ToYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate) else Year(@ToDate)+1 end
--select @fromYear,@toyear,@todate,@ProjCode,@Cardcode,@VoucherType,@GroupName
select a.u_category,a.docdate,g.name,d.CardCode,d.cardname,e.GroupName,SUBSTRING(CONVERT(VARCHAR(11), a.docdate, 113), 4, 8)as Month of invoiceraised,
b.seriesname,a.docnum,a.Project,0,a.doctotal,
paidamount= case when a.paidtodate is NULL then 0 else a.paidtodate end,
pendingamount= case when isnull(a.doctotal,0)-isnull(a.paidtodate,0) is null then 0 else isnull(a.doctotal,0)-isnull(a.paidtodate,0) end,
case when year(a.docdate) = @ToYear and month(a.docdate) = 3 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as March ,
case when year(a.docdate) = @ToYear and month(a.docdate) = 2 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Feb,
case when year(a.docdate) = @ToYear and month(a.docdate) = 1 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Jan,
case when year(a.docdate) = @FromYear and month(a.docdate) = 12 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Dec,
case when year(a.docdate) = @FromYear and month(a.docdate) = 11 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Nov,
case when year(a.docdate) = @FromYear and month(a.docdate) = 10 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Oct,
case when year(a.docdate) = @FromYear and month(a.docdate) = 9 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Sept,
case when year(a.docdate) = @FromYear and month(a.docdate) = 8 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Aug,
case when year(a.docdate) = @FromYear and month(a.docdate) = 7 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as July,
case when year(a.docdate) = @FromYear and month(a.docdate) = 6 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as June,
case when year(a.docdate) = @FromYear and month(a.docdate) = 5 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as May,
case when year(a.docdate) = @FromYear and month(a.docdate) = 4 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as April,
--case when a.docdate = (select f_refdate from ofpr where year(f_refdate)=year(a.refdate) then a.doctotal-c.paidtodate else 0 end as Pre-Yr
nodocsum=isnull(f.nodocsum,0),0 as PreviousFY
from oinv a
left join nnm1 b on a.series=b.series
inner join INV1 c ON a.DocEntry = c.DocEntry
inner join OCRD d ON d.CardCode=a.CardCode
left join ocpr g on g.cardcode=d.cardcode
Inner join OCRG e on e.GroupCode=d.GroupCode and e.grouptype='c'
LEFT JOIN ORCT f ON a.DocEntry = f.DocEntry
where
a.docstatus='O' and
case when a.doctotal-a.paidtodate is null then 0 else a.doctotal-a.paidtodate end >= 0
Reds,
Sampath kumar devunuri.Hi,Gordon Du ,
We are designing through Crystal reports 2008 only. Based on SQL query how we can maintain History of Document status and date in table. Please give me your advise how we can rectify this problem. Kindly find above query.
Regds,
Sampath Kumar. -
Parameter Query for True or False values
I have what seems like a painfully simple task and it has me stopped dead. I reviewed a similar thread, and the answers there don't seem to apply. Working in Crystal 11.5 with an MS SQL database.
I am pulling data from vwCommmittees. There is a field in this view called IsActive. I want to create a committee list report that will allow the user to select only the active committees or all committees.
A SQL select statement that says where dbo.IsActive = '1' will return only the active committees.
In Crystal reports, if I place the IsActive field on the report, it returns with "True" or "False."
When I create a parameter for this field, I find that 1) I can't see the parameter in the report expert -- my only choices are Is any value, Is true, Is false or Formula.
I've made several attempts to create a formula and nothing is working. It's not clear to me wheter I should be creating a static or a dynamic parameter. When I choose boolean as the type, that doesn't seem to help. I tried a dynamic parameter which gave me true and false values, but don't seem to work.
Any pointers on dealing with this kind of parameter query would be greatly appreciated.
Sincerely,
Ridge (in New Joisey)Hi..
Create a static parameter and give the default values like
0 and 1
In Record Selection check like..dbo.IsActive = {?parameter}
If the above is not working for you, then create a formula
like..
If dbo.IsActive = '1' then
"Active"
Else "In Active"
Place this formula on your report and create a static parameter with default values Active and In Active.
In record selection filter the above.
Thanks,
Sastry -
Query in Insert statement with JDBC Rx adapter
Hi,
This is a FILE to JDBC scenario.
My target datatype is like this with sample payload values
statement_s
statement_s
action='INSERT"
access
A=1234
B=1002
key
A=1234
B ="10%"
compareOperation= LIKE
A(1..1) is primary key in DB and B(0..1) colunm is an optional one.
I want to know if such kind of Insert query with(LIKE operator) is possible.
Please reply me ASAP.
Edited by: ram pranav on Feb 18, 2009 10:28 PMHi Ram,
IN case of "UPDATE_INSERT", you can use the KEY tag in your structure. Also you can provide LIKE as an attribute to the KEY element as follows :
<key1>
<col4 compareOperation=u201DLIKEu201D>val%</col4>
</key1>
But when you are trying to insert the data_, the <key> tags will be ignored and only <access> will be considered._
action=UPDATE_INSERT
The statement has the same format as for the UPDATE action. Initially, the same action is executed as for UPDATE. If no update to the database table can be made for this action (the condition does not apply to any table entry), values of the table described in the <access> element are inserted in accordance with the description of the action INSERT. <key> elements are ignored in this case.
The response document has the following format; one of the two values is always 0 because either an UPDATE or an INSERT action is always executed:
Go through the link I have provided earlier.
Thanks,
Pooja Pandey -
Tabular model with Direct Query issue
Hi,
i am creating a tabular model - Direct Query option. I am using a kind of below query to import data,
Declare @TEST as Table (TestID int, TestName varchar(20))
Insert into @TEST
Select 1, 'TEst1' Union
Select 2, 'TEst2'
Select * from @TEST
But the Import fails with an error similar to below,
OLE DB or ODBC error. An error occurred while processing the partition 'Query_``````````' in table 'Query_````````'. The current operation was cancelled because another operation in the transaction failed.
Any idea, why it is failing ? or is it like we shouldn't use declare statement in the Query area ?
Please reply ...Thanks in advance !
--------------------------- Radhai Krish | Golden Age is no more far | --------------------------I'm pretty sure that the query would have to be a single statement so the declare statement would be causing issues.
So just doing this as a single union query should work:
Select 1 as TestID, 'TEst1' as TestName Union
Select 2, 'TEst2'
http://darren.gosbell.com - please mark correct answers -
Hi,
Kindly view the query.
select loan_id,status_date from loan_status_history group by loan_id,status_date
How to select the records with latest(max) status_date in each group?
regards
Mathewyou use aggregation function on one of the selected column and group by others.
in your example,
select load_id, max(status_date) from loan_status_history group by load_id -
Problem in framing a query in stored procedure
I have problem in framing a query string.
This query contains a link (ie hyperlink). In this i have to add single quotes and double quotes in the middle. I dont know how to frame this query. I am sending this query. I am getting an error message "missing double quotes in the expression". So kindly frame this query.
Thanks in advance.
Here is my query
sql_Query := 'SELECT DISTINCT(topic_name) TOPIC,course_title TITLE,'||'''''||course_description||'||
'''''"Description",'||'''COURSE''"ModuleName"'||
' FROM V_COURSE '||' WHERE COURSE_ID IN('||'''NOTHING'''||')';Don't try to write a query like this in one time. Do it step by step (adding the next string every time), print the result with dbms_output.put_line, and see at which point the error occurs.
-
Query to insert a row in a table with same values except 1 field.
Suppose I have a table with 100 columns(fields).
I want to insert a row with 99 fileds being the same as previous ones except one fileld being different.
The table doesn't have any constraints.
Kindly suggest a query to solve the above purpose..And for much more lazy people, a desc of table is shorter to write. :-)
Then copy & paste into any editor, then mode column to add a comma after every column name in one shot.Or have the system do it for you. Be lazy.
SELECT Column_Name || ',' FROM User_Tab_Columns where Table_Name = '';
Indeed, it can be converted to a script called desc(.sql)
SELECT Column_Name || ',' FROM User_Tab_Columns where Table_Name = '&1' ORDER BY Column_Id;
Then desc or @desc. -
Hi experts,
i kindly need a query that when an outgoing payment is made with doctype (S OR C),
the invoice numatcard and invoice remarks will be picked into the two UDF's created.
Urgent help will be appreciated.
Regards
JusticeHi Justice,
Create 2 UDF at Row Level in Outgoing payment, First for AP Invoice Remark and Second for AP Invoice NumAtCard.
Then Place below two Query in Respective Columns..
This FMS is for Remarks
Select T0.[Comments] From OPCH T0 Where T0.DocNum = $[$20.1.0]
This FMS is for NumAtCard
Select T0.[NumAtCard] From OPCH T0 Where T0.DocNum = $[$20.1.0]
After putting both FMS in Respective Column then Make these to FMS on Auto Refresh on Customer Name.
Hope this helps
Regards::::
Atul Chakraborty -
Collection query to get the Linux machines details
Hi,
Can I get the collection query to create list of Linux machines . Please help me to getHello, I think, you are asking about SCCM collections !??? if yes, kindly post your query no SCCM forums.
if not, please elaborate your question?
Devaraj G | Technical solution architect -
How to find query names in transport?
Hi Experts,
We have collected around five queries for transport. But in SE10, we do not see the query names. How to find out the query names there?
With Kind Regards,
KannanOpen query in query designer.
From 'Properties' window (right side Window) dropdown select query.
From 'Advanced' tab copy the UID. U can search that in SE09.
OR
Copy that query ID from SE10, use table RSZELTDIR with that ID. -
I need query for Q1,Q2,Q3 data. Q is quarter.
That is Q1=1 to 4
Q2=4 to 8
Q3=9 to 12
I give above these parameters for this query.
I select Q1 run this query. same run as Q2,Q3.
(select d.valuedoc,
(case when (d.el4='E9000') then 'Other Revenue' else '1' end ) as Line,
h.yr,
h.period
from oas_dochead as h, oas_docline as d
left outer join oas_grplist as g
on d.el4=g.code and d.cmpcode=g.cmpcode and g.grpcode in ('21ONSITE', '21OFFSITE')
where d.docnum=h.docnum
and d.doccode=h.doccode
and d.cmpcode=h.cmpcode
and (h.yr between ?Year? - 3 and ?Year? and h.period between 1 and 4)
)>
I need query for Q1,Q2,Q3 data. Q is quarter.
That is Q1=1 to 4
Q2=4 to 8
Q3=9 to 12Nope - they're not quarters - they're thirds.
Quarters are 1-3, 4-6, 7-9, 10-12
Kindly repost your query within
.... tags - it's unreadable otherwise.
Also, see my .sig for other information to post - DB version, OS
&c.
Paul...
When asking database related questions, please give other posters
some clues, like OS (with version), version of Oracle being used and DDL.
Other trivia such as CPU, RAM + Disk configuration might also be useful.
The exact text and/or number of error messages is useful (!= "it didn't work!"). Thanks.
Furthermore, as a courtesy to those who spend time analysing and attempting to help,
please do not top post and do try to trim your replies!
Maybe you are looking for
-
How do I get the App Store app back on my iPhone
Somehow, my kids managed to delete the App Store application from my iPhone 4. How do I get it back? I can't update any apps or download new ones.
-
Why can't I upload a song to my iPad 2 ?
When I try upload a certain group of songs from Itunes (Itunes do play them) to my iPad these appears: I've check the formats and they are MP3 kind and MPEG-1, Layer 2. As all my other songs. See? Also, my iPad has enough memory for all these songs.
-
Can a gift card be applied as a credit to an already purchased iPhone?
I recently sent my iPhone 4S back to Apple's recycling program through PowerOn. I am waiting for them to receive and audit it and then send me an Apple gift card for the determined amount. I want to purchase the iPhone 5 when it comes out on Friday,
-
I'm developing a lot of form for a customer who needs to manage conformity of received products so he needs to print some forms that have to be sent to supplyer. Question is: How can I print only data inside form without stars rating - number of visi
-
Does anyone know what the accountsd process is?
Does anyone know what the accountsd process is? I see this running in Activity Monitor.