gpt4 book ai didi

sql - Select 语句中的情况

转载 作者:行者123 更新时间:2023-12-01 16:40:14 25 4
gpt4 key购买 nike

我有一个 SQL 语句,其中包含来自 SELECTCASE,但我无法正确执行它。你们能给我看一个CASE的例子吗,其中案例是条件,结果来自案例。例如:

     Select xxx, yyy
case : desc case when bbb then 'blackberry';
when sss then 'samsung';
end
from (select ???? .....

结果显示的位置

 name                         age       handphone
xxx1 yyy1 blackberry
xxx2 yyy2 blackberry

最佳答案

MSDN 是此类有关语法和用法的问题的一个很好的引用。这是来自 Transact SQL 引用 - CASE 页面。

http://msdn.microsoft.com/en-us/library/ms181765.aspx

USE AdventureWorks2012;
GO
SELECT ProductNumber, Name, "Price Range" =
CASE
WHEN ListPrice = 0 THEN 'Mfg item - not for resale'
WHEN ListPrice < 50 THEN 'Under $50'
WHEN ListPrice >= 50 and ListPrice < 250 THEN 'Under $250'
WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000'
ELSE 'Over $1000'
END
FROM Production.Product
ORDER BY ProductNumber ;
GO

如果您使用 SQL Server,您可能需要查看的另一个好网站是 SQL Server Central 。这里有大量的资源可供您学习 SQL Server 的任何领域。

关于sql - Select 语句中的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14189216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com