473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

plz solve this query as soon as possible

Main table


inst flag
1 y
2 y
3 y
4 n
5 n
6 y
10 n
11 n
12 n
20 y
21 y


ouput should be contain 2tables which r print &wastage table(use cursor)

print table
from to
1 3
6 6
20 21


wastage table
from to
4 5
10 12
Dec 24 '07 #1
5 1301
debasisdas
8,127 Expert 4TB
kindly post what you have tried sofar.
Dec 24 '07 #2
amitpatel66
2,367 Expert 2GB
Hi Komalrade ,

Welcome to TSDN!!

Please make sure you follow POSTING GUIDELINES every time you post in this forum!!

MODERATOR
Dec 24 '07 #3
Here's a start...

Good luck!

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT NVL (start_range,
  2.                      LAG (start_range) OVER (ORDER BY inst)
  3.                     ) AS "from",
  4.                 NVL (end_range,
  5.                      LEAD (end_range) OVER (ORDER BY inst)
  6.                     ) AS "to"
  7. FROM            (SELECT inst,
  8.                         flag,
  9.                         start_range,
  10.                         end_range
  11.                  FROM   (SELECT inst,
  12.                                 flag,
  13.                                 CASE
  14.                                   WHEN (flag <> LAG (flag) OVER (ORDER BY inst))
  15.                                 OR    (LAG (flag) OVER (ORDER BY inst) IS NULL) THEN inst
  16.                                   ELSE NULL
  17.                                 END start_range,
  18.                                 CASE
  19.                                   WHEN (flag <> LEAD (flag) OVER (ORDER BY inst))
  20.                                 OR    (LEAD (flag) OVER (ORDER BY inst) IS NULL) THEN inst
  21.                                   ELSE NULL
  22.                                 END end_range
  23.                          FROM   main_table)
  24.                  WHERE  (   start_range IS NOT NULL
  25.                          OR end_range IS NOT NULL)
  26.                  AND    flag = 'y')
  27. ORDER BY        "from"
Dec 26 '07 #4
can u plz tell in detail ? cant understand query,
Jan 1 '08 #5
Following is the result of my research of one hour:

For print table:
Expand|Select|Wrap|Line Numbers
  1. SELECT MIN(inst), MAX(inst) FROM( 
  2. SELECT inst, inst-ROWNUM AS criteria FROM tmp 
  3. WHERE flg='y' ORDER BY inst) GROUP BY criteria
For waste table:
Expand|Select|Wrap|Line Numbers
  1. SELECT MIN(inst), MAX(inst) FROM( 
  2. SELECT inst, inst-ROWNUM AS criteria FROM tmp 
  3. WHERE flg='n' ORDER BY inst) GROUP BY criteria
Enjoyed a lot in solving this problem. Hope it works for you
Jan 3 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works...
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
5
by: Rated R1 | last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got and see if someone can please help me. Email me and we can set something up as Id even be willing to pay for your...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
5
by: bruce24444 | last post by:
What I have is a database which tracks assigned files to a certain people which is generated by a form and then recorded into a table. Table are as follows “Staff” “Loss_Type” and...
1
by: bruce24444 | last post by:
First of all I'm new to the forum and am working on my first database. So far I think I've done not too bad but have hit a stumbling block for which I'm not sure how to get around. What I have is...
1
by: jimjack145 | last post by:
Hi All, I have one form with two multi select list box. I want to create query when user select value from it and click for result page. However i search on net but not find any code example....
4
by: MikeSA | last post by:
Hi All I have a Orders query and a Order Details query both derived from their respective tables, of which the Order Details query then eventually becomes a sub-form of the Form Orders. Standard...
2
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.