在一个查询中选择计数和其他记录

编程入门 行业动态 更新时间:2024-10-12 16:21:36
本文介绍了在一个查询中选择计数和其他记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下查询

select main_cat_name,cat_url from mf_main order by main_cat_name

这将返回表的全部数据.现在我想统计该表的总行数.我可以使用另一个查询来做到这一点,但是如何在一个查询中使用它们呢?

This returns whole data of my table.Now i want to have count of the total rows of this table.I can do it using another query but how can i use them in one single query???

我要两个数据ONE:-表的两行:-计数 我如何在一个查询中拥有它

I want two data ONE :- the rows of the table TWO:- the count how can i have that in one single query

我尝试了这个,但是它给出了正确的计数,但是仅显示表格的第一行:

I tried this but it gives correct count but displays only first row of the table :

select count(cat_id),main_cat_name,cat_url from mf_main order by main_cat_name

推荐答案

您可以尝试使用分组方式,例如:

You can try with Group By like:

SELECT count(cat_id), main_cat_name, cat_url FROM mf_main GROUP BY main_cat_name, cat_url ORDER BY main_cat_name

我希望正确的解决方案:

Right solution i hope:

这就是您想要的:)

SELECT x.countt, main_cat_name, cat_url FROM mf_main, (select count(*) as countt FROM mf_main) as x ORDER BY main_cat_name

如果您使用mysql,您将像我一样拥有"as".对于其他人,db可能没有as(例如oracle)

If you use mysql u have "as" like i did. For others db may be without as (like oracle)

更多推荐

在一个查询中选择计数和其他记录

本文发布于:2023-10-26 18:18:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!