我正在写这样的查询...
select consumer_name,count(select * from consumer where product='TTT')
from consumer;
我想要过滤计数...对此有什么完美的查询?
答案 0 :(得分:2)
也许是这样的:
select
consumer_name,
(
SELECT
COUNT(*)
FROM
consumer AS tbl
WHERE
tbl.product='TTT'
)
from
consumer;
答案 1 :(得分:0)
尝试
select
consumer_name, COUNT(your_column_name which you want to count)
from consumer
WHERE tbl.product='TTT' group by colusumer_id;
答案 2 :(得分:0)
如果要求隐藏计数(以及输出中的任何内容),您可以使用别名:
select consumer_name,
count(select * from consumer where product='TTT') as A /*or any thing that you want */
from consumer;
或
select
consumer_name,
(
SELECT
COUNT(*)
FROM
consumer AS tbl
WHERE
tbl.product='TTT'
) as A
from
consumer;
答案 3 :(得分:0)
您可以使用SUM
代替COUNT
并按CASE
或DECODE
DECODE
一个
SELECT consumer_name, SUM(DECODE(product, 'TTT', 1, 0))
FROM consumer;
CASE
一个
SELECT consumer_name, SUM(CASE WHEN product = 'TTT' THEN 1 ELSE 0 END))
FROM consumer;