【发布时间】:2014-12-29 21:50:14
【问题描述】:
我有 2 个表,“部门”和“文档”。
表department
| doc_id | dept_name |
----------------------------------
| 1 | Information Technology|
| 2 | Software Development |
| 3 | Human Resource |
| 4 | Accounting |
| 5 | Support |
表document
| doc_id | doc_name | author | description | department |
----------------------------------------------------------------------------
| 1 | Maps | User1 | sample | Information Technology |
| 2 | Audits | User3 | sample | Software Development |
| 3 | Image | User1 | sample | Information Technology |
| 4 | Papers | User4 | sample | Human Resource |
| 5 | Print Screen| User1 | sample | Software Development |
| 6 | Transaction | User3 | sample | Accounting |
| 7 | Graph | User1 | sample | Support |
| 8 | Excel | User1 | sample | Information Technology |
现在,我想显示包含两列的表格:department 和 total_doc。
输出:
| department |total_doc|
-----------------------------------
| Information Technology| 3 |
| Software Development | 2 |
| Human Resource | 1 |
| Accounting | 1 |
| Support | 1 |
我想显示部门内的全部文档,并按升序排列。
这是我的问题。(不确定)
SELECT department, count(doc_name) as 'total_doc' FROM tbl_document GROUP BY doc_name
我在 Codeigniter 中使用 MVC 模式。
$this->db->select("department, count(doc_name) as 'total_doc'");
$this->db->from('document');
$this->db->group_by('doc_name');
另外,我怎样才能在表格中显示这个?喜欢在 html 中使用 foreach 吗?
【问题讨论】:
-
你能把 .sql 文件发给我,以便我可以通过在我的系统中进行测试来提供给你。
-
我不能!我只是在我们的组织中维护一个程序,我的 sql 上的一些数据是机密的。
标签: php mysql sql-server codeigniter