2

以下はクエリです

select *,  "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

しかし、SQL エラーがあり、FROM の前に重要な単語がありません。

caseすべての列を選択したい場合に使用する青写真は何ですか?

4

5 に答える 5

7

これを試して

select *, 
  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 AS [Price Range]
  FROM Production.Product
      ORDER BY ProductNumber
于 2012-09-26T08:23:14.273 に答える
4

末尾の後に列名を入れてください。クエリは正しくありません。

SELECT p.ProductName, 
  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 AS Price_Range
FROM Product p

しかし、製品と顧客の間にリンクはありますか

于 2012-09-26T08:15:54.097 に答える
2

aliasの case ステートメントの後に来る必要があると思いますOracle。これを試して、

SELECT  *  ,
        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 AS "Price Range"
FROM    Production.Product
ORDER BY ProductNumber
于 2012-09-26T08:12:51.300 に答える
1

そのはず:

 select *, "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
于 2012-09-26T08:20:22.693 に答える
1

なぜあなたは選んでいfrom customerますか?

select *, 
  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 as [Price Range]
  FROM Production.Product 
      ORDER BY ProductNumber 
于 2012-09-26T08:15:09.377 に答える