Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / HELP !!!!!!!!!! / 3 сообщений из 3, страница 1 из 1
24.07.2002, 13:31:59
    #32038469
mxn
mxn
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
HELP !!!!!!!!!!
ПОМОГИТЕ !
ЕСТЬ ДВА ЗАПРОСА
ОЧЕНЬ НУЖНО ОБЪЕДЕНИТЬ ИХ В ОДИН. КАК ???
(что б значение sum(transactions.amount), было как столбец во втором запросе)
================
select
sum(transactions.amount)
from guest, transactions, z_trancode
where guest.ghacct=@history and transactions.account=guest.account and
transactions.tran_code=z_trancode.code and z_trancode.trantype in ("200", "RV","FB")
GROUP BY guest.account

================
select @history,guest.account,
convert(varchar(10),guest.arrival,103),
convert(varchar(10),guest.departure,103),
guest.room
from guest
where guest.ghacct=@history
...
Рейтинг: 0 / 0
24.07.2002, 13:52:28
    #32038486
VVG_
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
HELP !!!!!!!!!!
Как-нибудь так наверное:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
select @history,guest.account, 
convert(varchar( 10 ),guest.arrival, 103 ), 
convert(varchar( 10 ),guest.departure, 103 ), 
guest.room,Amounts.Amount 
from guest 
inner join 
(select guest.account,
sum(transactions.amount) as Amount
from guest, transactions, z_trancode 
where guest.ghacct=@history and transactions.account=guest.account and 
transactions.tran_code=z_trancode.code and z_trancode.trantype in ( "200 ",  "RV" , "FB" ) 
GROUP BY guest.account) as Amounts on Amounts.guest.account=guest.account
where guest.ghacct=@history
...
Рейтинг: 0 / 0
24.07.2002, 14:02:27
    #32038491
ВладимирМ
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
HELP !!!!!!!!!!
Если поле guest.account является уникальным идентификатором для guest, то все решается очень просто:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
select 
@history as history,guest.account, 
convert(varchar( 10 ),guest.arrival, 103 ) as arriv, 
convert(varchar( 10 ),guest.departure, 103 ) as depart, 
guest.room, 
sum(transactions.amount) 
from guest, transactions, z_trancode 
where guest.ghacct=@history and transactions.account=guest.account and 
transactions.tran_code=z_trancode.code and z_trancode.trantype in ( "200 ",  "RV" , "FB" ) 
GROUP BY history,guest.account, arriv, depart, room


Ну, а если на одно значение account в таблице guest по данным условиям может приходится несколько значений arrival, departure и room, то тогда только через объединение как и предложил VVG_
...
Рейтинг: 0 / 0
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / HELP !!!!!!!!!! / 3 сообщений из 3, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]