Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Вебмастеру (http://forum.oszone.net/forumdisplay.php?f=22)
-   -   COUNT(*) (http://forum.oszone.net/showthread.php?t=52931)

slaine 20-08-2005 22:46 349543

COUNT(*)
 
Можно ли в одном запросе подсчитать строки сразу в нескольких таблицах, например в четырёх?

Vlad Drakula 20-08-2005 23:07 349546

slaine
естли допустимо стобы результат выводился в разных строках, то без проблемм...

slaine 20-08-2005 23:42 349549

да в разных строках..

Vlad Drakula 21-08-2005 00:02 349554

slaine
тогда можно смотреть в сторону UNION...

vadimiron 21-08-2005 00:04 349555

slaine
Речь идёт о MySQL
Насколько я понимаю, то нельзя
Почитайте тут , в комментарии к этой статье написано
Цитата:

If you are using SELECT DISTINCT on a complex join clause, you might be stumped to find the count without returning the whole recordset. For example:

SELECT DISTINCT COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id

Will not return the same number for 'theCount' as you would have using mysql_num_rows and:

SELECT DISTINCT table1.user_id FROM table1, table2 WHERE table1.user_id = table2.user_id

This is because DISTINCT affects the user_id, not the count. If you try something like:

SELECT DISTINCT table1.user_id, COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id

Then you'll get an error saying there's no GROUP BY clause. The key is to collapse all of the rows using GROUP BY NULL:

SELECT DISTINCT table1.user_id, COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id GROUP BY NULL

slaine 21-08-2005 00:30 349559

Круто.. я делал точно так же, как в этой статье.

Vlad Drakula 21-08-2005 11:33 349601

vadimiron
не вводи человека в заблуждение... (веть сказано что можно в разных строках!)

slaine
в SQL есть оператор UNION он вам поможет...

slaine 21-08-2005 17:51 349650

спасибо, буду пробывать.


Время: 11:47.

Время: 11:47.
© OSzone.net 2001-