【问题标题】:Count rows in table where and then get the id and print them from another table计算表中的行,然后获取 id 并从另一个表中打印它们
【发布时间】:2013-01-15 20:37:11
【问题描述】:

我如何使用 Codeigniter 或 SQL 来计算它们具有相同值的行数(表:响应,行:task_id),然后使用 task_id 从包含信息的表中打印出结果(表: 任务)。

希望你能理解。

【问题讨论】:

  • 加入和 group_by,但无法让他们工作。
  • 也许你可以使用 sqlfiddle.com 并发布其中一个来工作。
  • 你想要计数还是行,如果是行,根据什么顺序和选择,给定的行不是表中的列?请记住,任务日期升序排列的第 1 行是降序排列的 row(n)...

标签: php mysql sql codeigniter codeigniter-2


【解决方案1】:

虽然我不能 100% 确定我理解您的问题,但如果您尝试获取响应表中的任务 ID 计数并将其链接到任务表,您是否尝试过这样的操作:

select t.taskid, t.taskname, r.taskcount
from tasks t
join 
(
  select taskid, count(taskid) taskcount
  from responds
  group by taskid
) r 
  on t.taskid = r.taskid

还有SQL Fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    相关资源
    最近更新 更多