我需要取这个数据集的平均值,但列的格式为money / text。
我试过了:
SELECT
sfo_calendar.calender_date,
AVG(CAST(sfo_calendar.price AS int) avg_price
FROM
sfo_calendar
GROUP BY sfo_calendar.calender_date;
但是不断收到这个错误:
错误:整数的输入语法无效:“$ 101.00”SQL状态:22P02
问题是$符号,它不能转换为int,因此您可以尝试将其替换为零,因为它位于价格的开头且不会影响该值。
SELECT
sfo_calendar.calender_date,
AVG(CAST(replace(sfo_calendar.price,'$',0) AS int) avg_price
FROM
sfo_calendar
GROUP BY sfo_calendar.calender_date;