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