
1 fangzhzh Jul 9, 2013 可不可以不要select *, 表结构一变,你这代码就随时可能爆炸啊 |
3 fangzhzh Jul 9, 2013 除了select*不能接受, 你这写法我能接受 |
4 sutar Jul 9, 2013 JOIN |
7 lichao Jul 9, 2013 select category.field1, item.field2 from category, item whre item.categoryID = category.categoryID |
10 lichao Jul 9, 2013 select category.categoryName, count(item.itemID) as YOUR_COUNT from category, item where item.categoryID = category.categoryID group by category.categoryID |
11 lichao Jul 9, 2013 select category.categoryID, count(item.itemID) as YOUR_COUNT from category, item where item.categoryID = category.categoryID group by category.categoryID |
12 cdfmr Jul 9, 2013 select category, count(*) from item group by category,将此临时表与category表做联合查询。 |
13 msg7086 Jul 9, 2013 |
14 master Jul 9, 2013 话说为什么不用JOIN ? 比如像这样: SELECT category.*, COUNT(a target="_blank" href="http://item.id" rel="nofollow noopener">item.id) as item_count FROM category LEFT JOIN item ON item.category = category.id |
15 master Jul 9, 2013 抱歉,漏了 GROUP SELECT category.*, COUNT(item.id) as item_count FROM category LEFT JOIN item ON item.category = category.id GROUP BY category.id |