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

T-sql case 返回錯(cuò)誤值

T-sql case returns wrong value(T-sql case 返回錯(cuò)誤值)
本文介紹了T-sql case 返回錯(cuò)誤值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在努力讓我的 SQL 查詢工作.當(dāng)我的 IN 找不到一行時(shí),我想像圖片中的那樣返回一行,但我希望將 ifuserholdscertificate 設(shè)置為NO".

I'm struggling to get my SQL query to work. When my IN FAILS to find a row I want to return a row just like the ones in the picture but I want the ifuserholdscertificate to be set to 'NO'.

SELECT tuc.id,
       tu.firstName,
       tuc.uid,
       tuc.value,
       tc.name,
       count(tuc.value) over (PARTITION BY tuc.uid) AS 'amount',
       'certificate DESIRABLE' AS 'typeofthing' ,
       'YES' AS 'HasorNot',
       ifuserholdscertificate = CASE
                                    WHEN count(tuc.value) = 0 THEN 'NO'
                                    ELSE 'YES'
                                END
FROM t_user_certificates tuc,
     t_certificates tc,
     t_users tu
WHERE tuc.value IN (4,
                    12,
                    31)
  AND tuc.value = tc.id
  AND tu.id = tuc.uid
GROUP BY tuc.id,
         tu.firstName,
         tuc.uid,
         tuc.value,
         tc.name

這是查詢生成的數(shù)據(jù)!

正如您所看到的,即使有些人在數(shù)量行中只得到 2,它仍然不會(huì)獲取一行并將 ifuserholdscertificate 設(shè)置為NO".

As you can see even if some people only get 2 in the amount row it will still not fetch a row and set ifuserholdscertificate to 'NO'.

按請(qǐng)求更新!

select  tuc.id,
count(tuc.value) as 'counten',
tu.firstName,
tuc.uid,
tuc.value, 
tc.name, 
count(tuc.value) over (PARTITION BY tuc.uid) as 'amount',
'certificateDESIRABLE'  as 'typeofthing' ,
'YES' as 'HasorNot',
HasOrders = CASE
                WHEN count(tuc.value) = 0 THEN 'NO'
                ELSE 'YES'
            END
from t_user_certificates tuc                   
left outer join t_certificates tc
on tuc.value = tc.id
left outer join t_users tu
on tu.id = tuc.uid
GROUP BY tuc.id, tu.firstName, tuc.uid, tuc.value, tc.name

在計(jì)數(shù)中總是 1 并且總是是"

Alwyas one 1 in the count and always 'YES'

推薦答案

這可能更符合您的要求.你總是返回 1,沒(méi)有用戶沒(méi)有證書(shū),因?yàn)槟阍?where 子句中有 IN 位.因此,即使使用外連接,您也只能從 t_user_certificates 返回具有這些值的行.它實(shí)際上變成了一個(gè)內(nèi)部連接.ANSI 連接語(yǔ)法是您的朋友.它將 JOIN 邏輯與過(guò)濾器分開(kāi).

This might be more like what you're looking for. You're always returning 1, and no users w/o certificates because you have the IN bit in the where clause. So even with an outer join, you only return rows from t_user_certificates with those values. It effectively becomes an inner join. ANSI join syntax is your friend. It separates JOIN logic from filters.

SELECT tuc.id,
       tu.firstName,
       tuc.uid,
       tuc.value,
       tc.name,
       count(tuc.value) AS 'amount',
       'certificate DESIRABLE' AS 'typeofthing' ,
       'YES' AS 'HasorNot',
       ifuserholdscertificate = CASE
                                    WHEN count(tuc.value) > 0 THEN 'YES'
                                    ELSE 'NO'
                                END
FROM
    t_users tu
LEFT JOIN t_user_certificates tuc
    ON
    tu.id = tuc.uid
    AND 
    tuc.value IN
    (
        4
        , 12
        , 31
    )
LEFT JOIN
     t_certificates tc
    ON
    tuc.value = tc.id

GROUP BY tuc.id,
         tu.firstName,
         tuc.uid,
         tuc.value,
         tc.name;

這篇關(guān)于T-sql case 返回錯(cuò)誤值的文章就介紹到這了,希望我們推薦的答案對(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)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱(chēng)“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 国产成人精品久久二区二区91 | 久久精品中文 | 青久草视频 | 欧美性网站 | 国产精品99久久久精品免费观看 | 午夜电影一区二区 | 日韩日韩日韩日韩日韩日韩日韩 | 中文字幕一区二区三区不卡在线 | 美女爽到呻吟久久久久 | 国产日韩电影 | 天天搞夜夜操 | 亚洲精品视频网站在线观看 | 91视频精选 | 在线视频一区二区三区 | 亚洲狠狠爱 | 欧美黑人一级爽快片淫片高清 | 午夜精品91| 国产精品1 | 日韩久久成人 | 日本成人在线观看网站 | 99热这里只有精品8 激情毛片 | 一本大道久久a久久精二百 欧洲一区二区三区 | 国产精品久久久久久久久免费樱桃 | 久久精品国产一区二区电影 | 在线精品一区 | 拍拍无遮挡人做人爱视频免费观看 | 一区二区三区视频在线免费观看 | 久草福利 | 色中文在线 | 亚洲成av | 午夜不卡福利视频 | 国产精品视频在线免费观看 | 二区av| 成人日韩 | www.4虎影院 国产999精品久久久影片官网 | 亚洲网站在线观看 | 午夜精品久久久久久久久久久久久 | 欧美精品在线免费观看 | 国产91视频一区二区 | 免费一区二区三区 | 日日操视频 |