A tricky sql query
577162Mar 19 2009 — edited Mar 24 2009Hi,
I have data like this....
tab1 table has only one column col1 and it contains near about 3000 rows and all are numeric values.
tab2 has 3 columns col1,col2.col3
I want to generate a sql select statement with every four rows values of tab1 like the following.
Now say in the following example after row value 8 only three rows are there in tab1 then the select statement includes only those three values.
select *from tab1
col1
------
1
2
3
4 select col1,col2 from tab2 where col3 in(1,2,3,4)
5
6
7
8 select col1,col2 from tab2 where col3 in(5,6,7,8)
9
10
11 select col1,col2 from tab2 where col3 in(9,10,11)
I tried it in sql but while doing with case it is will throw error single row subquery returns many rows error.In pl/sql it is possible but how i can achieve it in sql?
Thanks in advance.