我有这两张桌子
/* CAT TYPE */
id name
1 Application
2 Brand
3 Feature
/* CATEGORIES */
id name url description type
1 Temperature temperature A complete range ... 1
2 Hobo hobo Hobo Loggers 2
3 USB usb USB loggers 3
4 Humidity humidity Humidity Loggers 1 我想在Cat Type下的每个类别的部分中显示它们,按照Cat Type id的顺序,然后是类别a-z的顺序。
因此,我想执行一个sql查询,它将对以上所有内容进行如下分组:
**Application**
- Temperature
- Humidity
**Brand**
- Hobo
**Feature**
- USB这是我当前的查询
SELECT * FROM categories
JOIN cat_type ON categories.type=cat_type.id
GROUP BY cat_type.id但它只对每个cat_type中的一个类别进行分组。我不确定如何让它显示所有这些内容。
发布于 2014-06-18 07:08:52
看起来你在寻找一个特定的订单,而不是一个群体。试试这个:
SELECT cat_type.Name as 'Heading', categories.name as 'Name' FROM categories
JOIN categories_type ON categories.type=cat_type.id
ORDER BY cat_type.idhttps://stackoverflow.com/questions/24274582
复制相似问题