我尝试使用许多不同的方法在SQLAlchemy中执行此代码,但是它们都不起作用。有人可以帮我吗
SELECT *
FROM news_nlp_sentences
WHERE sentence_id IN (SELECT MAX(sentence_id)
FROM news_nlp_sentences
WHERE "date_created" BETWEEN '2012-12-28' AND '2012-12-31'
AND "domain" = 'marketing_features'
GROUP BY sentence);
我尝试过
page = ConditionalSearch.query.filter(ConditionalSearch.sentence_id.in_(func.max(ConditionalSearch.sentence_id)), ConditionalSearch.domain == domain, ConditionalSearch.date_created>=from_date, ConditionalSearch.date_created<=to_date)
我什至尝试过
sql_str = "SELECT * FROM news_nlp_sentences WHERE sentence_id in (SELECT MAX(sentence_id) FROM news_nlp_sentences WHERE date_created BETWEEN {} AND {} AND {} = {} GROUP BY sentence);".format(str(from_date), str(to_date), str(column_name), str(key_word)) The sql_str give me error about BETWEEN
由于在数据库中有一些相同的句子,但word_id
有所不同,因此希望获得包含不同句子的列。如果我不尝试获取MAX(sentence_id)
,但又不想一遍又一遍地使用相同的句子,那么效果很好