sql—编写select语句,从db1.myguitarshop.products表中返回以下列:

of1yzvn4  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(257)

这个 ListPrice
使用 CAST 函数返回 ListPrice 小数点右侧有1位的列
使用 CONVERT 函数返回 ListPrice 列作为整数
使用 CAST 函数返回 ListPrice 列作为整数
我是这样开始的,但正如你所看到的,这是错误的,因为我没有使用 CAST 或者 CONVERT :

SELECT ProductName, ListPrice, DateAdded
FROM MyGuitarShop.Products
WHERE ListPrice > 500 AND ListPrice < 2000
ORDER BY DateAdded DESC

有人能帮我学语法吗?

des4xlb0

des4xlb01#

您可以尝试:

SELECT
    ListPrice,
    CAST(ListPrice AS decimal(10, 1)) AS ListPriceCast,
    CONVERT(decimal(10, 1), ListPrice) AS ListPriceConvert,
    CAST(ListPrice AS int) AS ListPriceInteger
FROM MyGuitarShop.Products;

为了获得一个精确到小数点后一位的数字的标价,我们可以将其转换为 decimal(10, 1) ,表示总精度为10位的数字,其中一位在小数点的右边。

相关问题