如何使用MySQL查詢某個(gè)列中相同值的數(shù)量統(tǒng)計(jì)
在利津等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),利津網(wǎng)站建設(shè)費(fèi)用合理。
可以通過用該字段分組計(jì)數(shù)獲得。例如:
select
col1,count(col1)
as
cnt
from
t1
group
by
col1;
這個(gè)查詢可返回表t1的字段col1中每個(gè)值的重復(fù)次數(shù)。
select?name,sum(num)?from?table?group?by?name
--group?by?分組查詢可以實(shí)現(xiàn),根據(jù)名稱分組查詢累加數(shù)量
select?*?from?(select?*?from?a?union?all?select?*?from?b)?T?where?name?in?(select?name?from?a??where?name?in(?select?name?from?b));
已經(jīng)經(jīng)過測試。
你是要查找數(shù)據(jù)庫中某個(gè)字段下的相同數(shù)據(jù)吧,我給你寫2個(gè)例子
(數(shù)據(jù)庫執(zhí)行效率高)
select * from dbo.MediafileInfo as a where
(VideoDownUrl IN (SELECT VideoDownUrl FROM MediafileInfo AS B WHERE A.ProgramID B.ProgramID))
(數(shù)據(jù)庫執(zhí)行效率低)
SELECT *
FROM MediafileInfo AS A
WHERE (SELECT COUNT(*) FROM MediafileInfo WHERE VideoDownUrl=A.VideoDownUrl)1