|
|
|
Помогите с запросом пожалуйста
|
|||
|---|---|---|---|
|
#18+
А можно сделать 3 GROUP BY один в другом. То есть надо объединить 3 запроса в один, а как не знаю ============================================= -- ПЕРВЫЙ select history.ghacct, convert(varchar(10),information.info), convert(varchar(8),(select info from information where code='TYPE' and information.account=history.ghacct)), history.name, history.sex, convert(varchar(10),history.dob, 103), history.zip, history.country, history.city, history.address, history.state, transactions.tran_code, sum(transactions.amount) from information, history, guest , transactions, z_trancode where information.code='N' and information.account=history.ghacct and history.ghacct=guest.ghacct and guest.account=transactions.account and transactions.tran_code=z_trancode.code and z_trancode.trantype in ('200', 'RV','FB') group by history.ghacct, information.info, history.name, history.sex, history.dob, history.zip, history.country, history.city, history.address, history.state, transactions.tran_code --ВТОРОЙ select sum(transactions.amount), transactions.tran_code, history.ghacct from transactions, z_trancode, information, history, guest where information.code='N' and information.account=history.ghacct and history.ghacct=guest.ghacct and guest.account=transactions.account and transactions.tran_code=z_trancode.code and z_trancode.trantype in ('200', 'RV','FB') and transactions.tran_code in ('206', '300', '215', '220', '999') group by transactions.tran_code, history.ghacct --ТРЕТИЙ select sum(transactions.amount), history.ghacct from transactions, z_trancode, information, history, guest where information.code='N' and information.account=history.ghacct and history.ghacct=guest.ghacct and guest.account=transactions.account and transactions.tran_code=z_trancode.code and z_trancode.trantype in ('200', 'RV','FB') and transactions.tran_code not in ('206', '300', '215', '220', '999') group by history.ghacct ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2002, 16:36:58 |
|
||
|
Помогите с запросом пожалуйста
|
|||
|---|---|---|---|
|
#18+
Наверное гоню,но ели ты хочеш обеденить результаты запросов используй union Код: plaintext 1. 2. 3. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2002, 16:46:34 |
|
||
|
Помогите с запросом пожалуйста
|
|||
|---|---|---|---|
|
#18+
Пробовал, пишет: Server: Msg 205, Level 16, State 1, Line 6 All queries in an SQL statement containing a UNION operator must have an equal number of expressions in their target lists. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2002, 17:26:23 |
|
||
|
Помогите с запросом пожалуйста
|
|||
|---|---|---|---|
|
#18+
Пишет правильно,ето я уже гнать начинаю,а вообще Вы что хотите с результируещим набором делать? можно поробывать написать,что-то типа Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. Так правда не все любят ,но мне помогает ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2002, 17:48:31 |
|
||
|
Помогите с запросом пожалуйста
|
|||
|---|---|---|---|
|
#18+
Подтверждаю. Правильно пишет. Для union надо, что бы во всех запросах было одинаковое количество полей и порядок их расположения по типам был одинаков. А у Вас, в первом запросе 13 полей, во втором запросе 3, в третьем - 2. Упорядчьте второй и третий запрос. Недостающие поля дополните фиктивными данными со значением NULL и типом, как в первом запросе. Что-то вроде convert(int,NULL). ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2002, 20:54:54 |
|
||
|
|

start [/forum/topic.php?fid=46&msg=32039190&tid=1821533]: |
0ms |
get settings: |
10ms |
get forum list: |
17ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
45ms |
get topic data: |
7ms |
get forum data: |
2ms |
get page messages: |
37ms |
get tp. blocked users: |
1ms |
| others: | 227ms |
| total: | 354ms |

| 0 / 0 |
