Текущий архив: 2003.02.24;
Скачать: CL | DM;
Вниз
Запрос по результатам другого запроса Найти похожие ветки
← →
de (2003-02-06 11:23) [0]Есть запрос:
select cast(t1.f1 as smallint) as n, t1.f2 as d
from table1 t1
union
select cast(t2.f1 as smallint) as n, t2.f2 as d
from table2 t2
Как сделать такой запрос по результатам этого запроса:
select n, max(d)
from (запрос) group by n
используя LocalSQL ???
← →
Наталия © (2003-02-06 11:27) [1]Поместить текст первого запроса в файл с расширением sql. Во втором запросе делать выборку из него.
← →
de (2003-02-06 11:34) [2]> Наталия © (06.02.03 11:27)
а как это сделать (выборку)?
← →
MsGuns © (2003-02-06 11:36) [3]Наташ, если есть самплы или ссылки на доку, кинь на мыло, будь ласка - меня технология эта очень интересует.
← →
Val © (2003-02-06 11:45) [4]>MsGuns © (06.02.03 11:36)
это называется Local SQl views - описано в Local SQL Guide
← →
Наталия © (2003-02-06 11:52) [5]Там это довольно скупо описано - буквально одно предложение. :)
------
In lieu of a table, a SELECT statement may retrieve rows from a Paradox-style .QBE file. This is an approximation of an SQL view.
SELECT *
FROM "customers.qbe"
------
Делается примерно так:
1 запрос: select * from table1 помещается в файл q1.sql в тот же директроий, что и программа.
2 запрос: select * from q1.sql
Если ничего не напутала, то вроде бы так оно и есть. :)
← →
Mike Kouzmine (2003-02-06 12:02) [6]Description
Local SQL does not support VIEWs is the traditional sense. It includes no CREATE VIEW statement. However, local SQL does provide an emulation that includes a lot of the functionality found in the traditional VIEW. This is the use of SQL (and QBE) queries that have been saved to a file.
An SQL statement can be saved to a text file and the file referenced in a local SQL statement. This process does not use an already existing result set, but executes the saved SQL statement to produce a result set on-the-fly that is used in the local SQL statement. All local SQL syntax rules apply to saved SQL statements.
To use an SQL statement as a VIEW, save it to a simple text file (with a .SQL extension), such as by using the Windows applet NotePad. Then, in a local SQL statement, mention the file by name where you would otherwise have named a base table. Enclose the file name in quotation marks. For example, assume the SQL statement below saved to the text file CA_CUST.SQL:
SELECT CustNo, Company
FROM "Customer.db"
WHERE (State = "CA")
Another local SQL statement can use the result set produced by this saved query by naming the .SQL file in the FROM clause of a SELECT statement:
SELECT *
FROM "CA_Cust.sql"
WHERE (SUBSTRING(Company FROM 1 FOR 1) <= "M")
Use of saved SQL queries is not limited to somple SELECT statements. They can also be used in place of tables in joins and can even be joined to the result sets of other saved queries. Using the previously mentioned CA_CUST.SQL file:
SELECT C.*, O.*
FROM "CA_Cust.sql" C
JOIN "Orders.db" O
ON (C.CustNo = O.CustNo)
Similarly, Paradox-style QBE (Query By Example) queries saved to .QBE files can be used in lieu of a base table in a local SQL statement. The QBE query below performs the same data retrieval as the earlier CA_CUST.SQL saved SQL file. It is saved with the name CA_CUST.QBE.
Query
ANSWER: :PRIV:ANSWER.DB
customer.db | CustNo | Company | State |
| Check | Check | CA |
EndQuery
As was the case with the saved SQL query, this saved QBE query is used in a local SQL statement in the exact same way.
SELECT C.*, O.*
FROM "CA_Cust.qbe" C
JOIN "Orders.db" O
ON (C.CustNo = O.CustNo)
Using saved QBE queries in local SQL statements affords you the ability to use functionality available just in QBE – but not local SQL – in local SQL statements. One example of such functionality is case-insensitive filtering on memo column contents.
Create QBE query files using Paradox, the Database Desktop utility, or a simple text editor.
← →
MsGuns © (2003-02-06 12:22) [7]>Mike Kouzmine (06.02.03 12:02)
Спасибо за помощь. Я, конечно, это читал и, скорее всего пробовал, но у меня не получилось чего-то, я это и закинул подальше. Наверное потому, что сохраненный исходный запрос (точнее, то, что он вернул) нельзя редактировать в отличие от временной таблицы, которая часто используется как "аккумулятор" информации при различных сложных алгоритмах выборок, расчетов и т.д. (например, когда создаются данные для сложных репортов)
Страницы: 1 вся ветка
Текущий архив: 2003.02.24;
Скачать: CL | DM;
Память: 0.48 MB
Время: 0.017 c