如何在同一查询中选择所有列和一个count(*) [英] How to select all columns, and a count(*) in the same query

查看:117
本文介绍了如何在同一查询中选择所有列和一个count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TSQL中经常使用以下查询:

In often use in TSQL the following query :

SELECT COUNT(*), * 
FROM CUSTOMER c 
WHERE c.Name like 'foo%';

当我尝试在Oracle SQL Developer中执行此查询时,它不起作用并抛出错误:

When I try to execute this query in Oracle SQL Developer it doesn't work and throws me an error:

缺少表情"

"Missing expression"

好的语法是什么?

谢谢.

推荐答案

一种方法是执行以下操作.这将导致每行的count(*)结果.但是要当心,有一个笛卡尔联接.如果您有很多行,例如'foo%',则该程序的效果会很差.

One approach is to do something like the following. This will result in a count(*) result for each line. But beware, there is a Cartesianjoin; if you have many rows like 'foo%' this will perform badly.

select a.cntr, c.*
from CUSTOMER c 
   , (select count(*) cntr
     from customer b
     where b.name like 'foo%' ) a
where c.name like 'foo%'

这篇关于如何在同一查询中选择所有列和一个count(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆