作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
id title numbers1 chicken 12 meat 13 fish 14 fish 25 meat 26 fish 37 chicken 28 chicken 3
I want to construct the following output as above. Anyone can help me calculate number of occurrence of column values but without GROUP BY(not remove same values) , let create "numbers" field same as above , thank
Normal , if use COUNT(*)
:
SELECT COUNT(*) FROM table GROUP BY title
但它删除了相同的值:
id title numbers1 chicken 32 meat 23 fish 3
我想保持相同的值,并像这样输出:
id title numbers1 chicken 1 2 meat 13 fish 14 fish 25 meat 26 fish 3 7 chicken 2 8 chicken 3
最佳答案
我假设您的问题是如何在示例输出中生成 numbers
列。如果这不正确,请澄清问题。
select id
, title
, (
select count(*)
from Table1 t2
where t1.title = t2.title
and t2.id <= t1.id
) as numbers
from Table1 t1
关于mysql - 如何计算列值出现的次数但没有GROUP BY(不是不同的值)mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14357688/
我是一名优秀的程序员,十分优秀!