Is there a way to create a loop query?
Closed due to the fact that the essence of the issue is not clear to the participants of D-side , Kromster , user194374, cheops , aleksandr barakin 18 Jun '16 at 7:37 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Emmm ... can be more detailed that you understand as cyclical request? - Barmaley
|
4 answers
Maybe you mean cursors?
... for rec in (select ...) loop end loop; ...
or pipelined functions?
- sorry, meant oracle - Sega
- A piece of code, Pawn language: Format (query, sizeof (query), "SELECT DISTINCT name FROM 'glav'"); result = SQL_Query (DB, query); while (SQL_HasResultSet (result) && SQL_FetchRow (result)) {SQL_FetchString (result, 0, Name, 64); Format (query, sizeof (query), "SELECT id FROM 'glav' WHERE name = '% s' ORDER BY time LIMIT 10", Name); result2 = SQL_Query (DB, query); while (SQL_FetchRow (result2)) {SQL_FetchString (result2, 0, steamId_resrv, 32); if (StrEqual (Id_resrv, steamId)) {num ++; }}} Here I am looking for a name and do a loop by name. It's just that there are a lot of lines and this cycle loads the server. - maza51
|
Examples of such "loops" are in the SQLite documentation.
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<1000000) SELECT x FROM cnt;
|
There is a While
, for example:
declare @counter int set @counter = 0 while @counter < 10 begin set @counter = @counter + 1 print 'The counter is ' + cast(@counter as char) end
- I mean query cyclical query! - maza51
|
The data you seek can be obtained in one request, the cycle is not needed.
I do not know if SQLLite supports such constructions, check:
select id from (select id, name , row_number() over (partition by name order by time) rw from 'glav' ) where rw <= 10
- I, unfortunately, do not know the features of SQLite syntax, so I can not tell you, the only other option is this, it will work in MS SQL: select id from (select id, name, row_number () over (partition by name order by time) rw from 'glav') as t where rw <= 10 - minamoto
- Our English-speaking friends from the resource, very similar to ours, say that the construction of "row_number () over (partition by" in sqlite will not work. Here is their conversation: stackoverflow.com/questions/4074257/… - minamoto
- Yes, it does not work. Sorry. Maybe there are more ways? - maza51
- I do not know the others, unfortunately. - minamoto
|