1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Pseudocode for SQL query

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 5, 2024 às 12:32.

  1. Stack

    Stack Membro Participativo

    Hi guys i have the following question,

    Assume tables foo(a int, b int) and bar(a int, b int) and assume you are given a stream ‘TableReader’ that reads rows from a table that has the following methods: tr.next() returns the next row of a type ‘row’ from the stream if there is a next row or null if there are no more rows. Assume columns can be accessed using row[columnName]. For example, to read rows from foo, you have to do the following: foo_stream = TableReader(‘foo’); row = foo_stream.next();

    row[‘a’] will return the value of column a and row[‘b’] will return the value of column b.

    Write a pseudocode to compute the results of the following SQL query which should return a list of rows: select foo.a, foo.b, bar.a, bar.b from foo, bar where foo.a = bar.a and foo.b <=100;

    Can anyone help me on this ? The solution i tried is:

    Foo_stream = TableReader(‘foo’);
    Bar_stream = tableReader(‘bar’);


    While(foo_stream.next())
    {
    {
    While(bar_stream.next())
    {
    Row_foo = foo_stream.next();
    Row_Bar =bar_stream.next();
    {
    If((row_foo[a] equals row_bar[a]) AND (row_foo < = 100))

    {
    Then print row_foo[a],row_foo, row_bar[a], row_bar
    }
    }
    }
    }


    But the above solution is of complexity O(n2), any better solution is appreciated.

    Continue reading...

Compartilhe esta Página