另一个菜鸟问题;如何在这里实现Count()?

时间:2010-05-06 15:28:49

标签: php sql mysql database

我有这个问题:

SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*, hem_inredning.*, hobby.*
FROM classified mt 
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id 
LEFT JOIN boende ON boende.classified_id = mt.classified_id 
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id 
LEFT JOIN business ON business.classified_id = mt.classified_id 
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id 
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id 
ORDER BY modify_date DESC

我需要在这里实现一个计数,只计算与你看到的JO​​INS组合的所有行。

我该怎么做?

SELECT COUNT(mt.*, fordon.* etc) FROM? //这种方法不起作用

由于

4 个答案:

答案 0 :(得分:3)

我删除了ORDER BY,因为COUNT

不需要
SELECT count(*)
FROM classified mt  
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id  
LEFT JOIN boende ON boende.classified_id = mt.classified_id  
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id  
LEFT JOIN business ON business.classified_id = mt.classified_id  
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id  
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id 

答案 1 :(得分:1)

SELECT COUNT(*) FROM (SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*,     hem_inredning.*, hobby.*
FROM classified mt 
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id 
LEFT JOIN boende ON boende.classified_id = mt.classified_id 
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id 
LEFT JOIN business ON business.classified_id = mt.classified_id 
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id 
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id) As A

答案 2 :(得分:0)

简单地说:

SELECT COUNT(*) FROM ...

答案 3 :(得分:0)

SELECT COUNT(*) FROM ...怎么样?我不确定你在想什么。