doufunuo4787 2013-06-30 06:52
浏览 50

在mysql结果上添加id [关闭]

Basically I am trying to join 2 tables and then return the result, below is the code I use. The problem is, lets say I want to grab the row only from 'Tina' to 'Ben'. It will not be possible since it has no ids, if I somehow include their ids, it will be in random numbers and not in orders. Is there anyway to handle this type of issue?

SELECT names.name, COUNT(item) AS items
FROM names
LEFT JOIN names_items 
  ON names.name = names_items.name
GROUP BY names.name
ORDER BY COUNT(item) DESC

The result would be something like this.

| Names  | Items  |
  Bob       60
  Tina      32
  Arthur    43
  Ben       21
  Ronie     54
  • 写回答

2条回答 默认 最新

  • doudinghan8319 2013-06-30 07:04
    关注

    you can create a column while creating all those table make the column name id and the properties of id will be

    -> id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    

    then you can use this id to select what u want

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教