久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

GROUP BY 同一列中的多個(gè)值

GROUP BY multiple values in same column(GROUP BY 同一列中的多個(gè)值)
本文介紹了GROUP BY 同一列中的多個(gè)值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有這個(gè) SQL 查詢:

I have this SQL Query:

select prefix, code, stat, complete, COUNT(*) as Count
from table
group by prefix, code, stat, complete
order by prefix, code, stat, complete

前綴"列是一個(gè)字母數(shù)字值 (0-9a-zA-z).我想要的是讓它如果前綴的值是一個(gè)數(shù)字,使數(shù)字等于0.如果它是一個(gè)字母,它會(huì)保持它的值.我試圖在 group by 子句下面添加以下行:

The column 'prefix' is an alphanumeric value (0-9a-zA-z). What I want is to make it so that if the value of prefix is a number, to make the number equal to 0. If it is a letter, it will keep its value. I have tried to add the following line beneath the group by clause:

(case when prefix like '%[0-9]%' then 0 else prefix end)

但我收到錯(cuò)誤消息將 varchar 值 'J' 轉(zhuǎn)換為數(shù)據(jù)類型 int 時(shí)轉(zhuǎn)換失敗.".

But I get an error "Conversion failed when converting the varchar value 'J' to data type int.".

是什么導(dǎo)致了這個(gè)錯(cuò)誤?如何讓前綴"列顯示 0 或一個(gè)字母?

What is causing this error? How can I get the 'prefix' column to display either 0 or a letter?

推薦答案

case when prefix like '%[0-9]%' then '0' else prefix end

你顯然也需要這個(gè)作為 GROUP BY 中的表達(dá)式:

You obviously also need this as the expression in the GROUP BY:

select 
    NewPrefix = case when prefix like '%[0-9]%' then '0' else prefix end, 
    code, 
    stat, 
    complete, 
    COUNT(*) as Count
from table
group by 
    case when prefix like '%[0-9]%' then '0' else prefix end, 
    code, stat, complete
order by 
    case when prefix like '%[0-9]%' then '0' else prefix end, 
    code, stat, complete

這篇關(guān)于GROUP BY 同一列中的多個(gè)值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

SQL - Select all when filter value is empty(SQL - 過(guò)濾器值為空時(shí)全選)
How and where do I set the MAXRECURSION option?(如何以及在何處設(shè)置 MAXRECURSION 選項(xiàng)?)
TABLOCKX versus SERIALIZABLE(TABLOCKX 與可序列化)
TSQL Constants... Use Variable or Literal?(TSQL 常量...使用變量還是文字?)
TSQL RIGHT String function not working(TSQL RIGHT 字符串函數(shù)不起作用)
What is the comparative speed of temporary tables to physical tables in SQL?(SQL中臨時(shí)表與物理表的比較速度是多少?)
主站蜘蛛池模板: 欧美日韩中文字幕 | 在线不卡视频 | 日韩成人av在线播放 | 黄色三级免费网站 | 日韩一区二区福利 | 日韩精品一区二区三区中文字幕 | 免费在线观看黄视频 | www.欧美视频 | 精品国产精品国产偷麻豆 | 911精品美国片911久久久 | 黄色网页在线观看 | 免费观看www | 欧美一区二区三区久久精品 | 高清人人天天夜夜曰狠狠狠狠 | 国产高清免费在线 | 亚洲人va欧美va人人爽 | 91久久久久 | 久草精品在线 | 91久久久久久 | 在线观看国产wwwa级羞羞视频 | 亚洲精品aⅴ | 亚洲一区二区三区在线免费 | 毛片电影 | 欧美日韩综合 | 久久国品片 | 无码国模国产在线观看 | 亚洲精品一区二区网址 | 2023亚洲天堂 | 二区视频| 黑人中文字幕一区二区三区 | 久久精品一区二区 | 成人福利网站 | 国产精品亚洲欧美日韩一区在线 | 亚洲狠狠 | 成人在线免费网站 | 欧美中文字幕一区二区三区亚洲 | 中文字幕一区二区三区精彩视频 | 欧日韩在线观看 | 蜜桃av人人夜夜澡人人爽 | 成人区精品一区二区婷婷 | www.黄色在线观看 |