选择案例时(选择)

SELECT CASE WHEN THEN (SELECT)(选择案例时(选择))
本文介绍了选择案例时(选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据产品类型为产品选择一组不同的结果.因此,如果我的产品应该是一本书,我希望它查找普通产品的 UPC 和艺术家,但这些细节无关紧要,而对于另一个产品,我想要一组完全不同的结果.

I am trying to select a different set of results for a product depending on a product type. So if my product should be a book I want it to look up the UPC and Artist for a normal product these details are however irrelevant and for another product I would want a completely different set of results.

SELECT CASE Product.type_id
    WHEN 10 THEN (
        SELECT 
        Product.product_id, 
        Product.type_id, 
        Product.product_name, 
        Product.UPC,
        Product_Type.type,
        CONCAT_WS(' ' , first_name, middle_name, last_name ) AS artistC 
        FROM Product, Product_Type, Product_ArtistAuthor 
        WHERE Product.type_id = Product_Type.type_id 
        AND Product.product_id = $pid
        AND Product.artist_id = Product_ArtistAuthor.artist_id
    )
    ELSE (
        SELECT 
        Product.product_id, 
        Product.type_id, 
        Product.product_name,
        Product_Type.type 
        FROM Product, Product_Type 
        WHERE Product.type_id = Product_Type.type_id 
        AND Product.product_id = $pid
    )
END
FROM Product 
WHERE Product.product_id = $pid

我不确定我哪里出错了

推荐答案

你可以试试 case 语句的其他格式

You Could try the other format for the case statement

CASE WHEN Product.type_id = 10
THEN
(
  Select Statement
)
ELSE
(
  Other select statement

)  
END
FROM Product 
WHERE Product.product_id = $pid

参见 http://msdn.microsoft.com/en-us/library/ms181765.aspx 了解更多信息.

See http://msdn.microsoft.com/en-us/library/ms181765.aspx for more information.

这篇关于选择案例时(选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)