我想创建一个table_2
和variable
不同的table_1
值的CREATE TABLE `table_2` AS
SELECT DISTINCT(CAST(variable AS NUMERIC))
FROM `table_1`;
,然后将它们从STRING预先转换为NUMERIC。
我的猜测是:
//index.pug
extends layout
block campground
- var campgrounds = '#{camps}'
.row
each campground in campgrounds
div.col-md-3.col-sm-6
div
img(src=`${campground.image}` class='img-thumbnail')
a(href=`/campgrounds/${campground._id}`)
h4.caption.text-center #{campground.name}
//app.js
app.get('/campgrounds', async (req, res) => {
try {
const camps = await Camp.find();
res.render('index', { camps: camps });
} catch (ex) {
res.status(500).send('internal error');
}
});
但这不起作用。 有什么建议吗?
答案 0 :(得分:1)
DISTINCT
不需要括号。您还需要命名输出列。试试这个:
CREATE TABLE `table_2` AS
SELECT DISTINCT CAST(variable AS NUMERIC) AS variable
FROM `table_1`;
答案 1 :(得分:0)
尝试一下:
CREATE TABLE `table_2` AS
SELECT CAST(variable AS NUMERIC)
FROM `table_1`
GROUP BY variable;