1
fangzhzh 2013-07-09 16:55:30 +08:00
可不可以不要select *, 表结构一变,你这代码就随时可能爆炸啊
|
2
iloveyou OP |
3
fangzhzh 2013-07-09 16:59:25 +08:00
除了select*不能接受, 你这写法我能接受
|
4
sutar 2013-07-09 17:01:24 +08:00
JOIN
|
7
lichao 2013-07-09 17:06:25 +08:00
select category.field1, item.field2 from category, item where item.categoryID = category.categoryID
|
10
lichao 2013-07-09 17:15:39 +08:00 1
select category.categoryName, count(item.itemID) as YOUR_COUNT from category, item where item.categoryID = category.categoryID group by category.categoryID
|
11
lichao 2013-07-09 17:16:13 +08:00 1
select category.categoryID, count(item.itemID) as YOUR_COUNT from category, item where item.categoryID = category.categoryID group by category.categoryID
|
12
cdfmr 2013-07-09 17:19:35 +08:00 1
select category, count(*) from item group by category,将此临时表与category表做联合查询。
|
13
msg7086 2013-07-09 18:37:24 +08:00
|
14
master 2013-07-09 20:08:18 +08:00
话说为什么不用JOIN ?
比如像这样: SELECT category.*, COUNT(item.id) as item_count FROM category LEFT JOIN item ON item.category = category.id |
15
master 2013-07-09 20:09:17 +08:00 1
抱歉,漏了 GROUP
SELECT category.*, COUNT(item.id) as item_count FROM category LEFT JOIN item ON item.category = category.id GROUP BY category.id |