Похожие чаты

Подскажите, как тут получить не поля, а количество записей? query =

(
select(
Advice.id,
Advice.dt,
Advice.with_recommendations,
AdvicePurposeVariety,
AdvicingAlgorithmVariety,
AdvicePurposeVariety,
AdviceReactionVariety,
EventVariety.name,
)
.distinct(Advice.id)
.where(and_(*filters_to_apply))
.outerjoin(AdvicePurposeVariety)
.outerjoin(AdviceReaction)
.outerjoin(AdviceReactionVariety)
.outerjoin(AdviceContext)
.outerjoin(AdvicingAlgorithmVariety)
.outerjoin(AdviceEvent)
.outerjoin(Event)
.outerjoin(EventVariety)
)
Такой вариант даёт ошибку
query = (
select(
func.count()
)
.distinct(Advice.id)
.where(and_(*filters_to_apply))
.outerjoin(AdvicePurposeVariety)
.outerjoin(AdviceReaction)
.outerjoin(AdviceReactionVariety)
.outerjoin(AdviceContext)
.outerjoin(AdvicingAlgorithmVariety)
.outerjoin(AdviceEvent)
.outerjoin(Event)
.outerjoin(EventVariety)
)
В первом запросе sql такой:
SELECT
DISTINCT ON (technological_section_1.advices.id) technological_section_1.advices.id,
....
Что бы получить кол-во надо, что бы было так
SELECT
count(DISTINCT technological_section_1.advices.id)
...

14 ответов

37 просмотров

там нужно делать select_from

Ручей-Виноградов Автор вопроса
Ilya Lyapin (Nestyreff)
там нужно делать select_from

так? query = ( select(func.count()).select_from() .distinct(Advice.id) .where(and_(*filters_to_apply)) .outerjoin(AdvicePurposeVariety) .outerjoin(AdviceReaction) .outerjoin(AdviceReactionVariety) .outerjoin(AdviceContext) .outerjoin(AdvicingAlgorithmVariety) .outerjoin(AdviceEvent) .outerjoin(Event) .outerjoin(EventVariety) )

Ручей-Виноградов Автор вопроса
Tishka17
ну укажи из чего селектить

query = ( select(func.count()).select_from( select() .distinct(Advice.id) .where(and_(*filters_to_apply)) .outerjoin(AdvicePurposeVariety) .outerjoin(AdviceReaction) .outerjoin(AdviceReactionVariety) .outerjoin(AdviceContext) .outerjoin(AdvicingAlgorithmVariety) .outerjoin(AdviceEvent) .outerjoin(Event) .outerjoin(EventVariety) ) ) Вроде так, по идеи, но тоже ошибка

Ручей Виноградов
query = ( select(func.count()).select_from( ...

select_from(…) в скобках то что у тебя было в этом запросе: select( Advice.id, Advice.dt, Advice.with_recommendations, AdvicePurposeVariety, AdvicingAlgorithmVariety, AdvicePurposeVariety, AdviceReactionVariety, EventVariety.name, )

Ручей-Виноградов Автор вопроса
Tishka17
на SQL как пишется селект?

SELECT count(DISTINCT technological_section_1.advices.id) FROM technological_section_1.advices -- LEFT OUTER JOIN common.advice_purpose_varieties ON common.advice_purpose_varieties.id = technological_section_1.advices.purpose_variety_id LEFT OUTER JOIN technological_section_1.advice_reactions ON technological_section_1.advices.id = technological_section_1.advice_reactions.advice_id -- LEFT OUTER JOIN common.advice_reaction_varieties ON common.advice_reaction_varieties.id = technological_section_1.advice_reactions.variety_id LEFT OUTER JOIN technological_section_1.advice_contexts ON technological_section_1.advices.id = technological_section_1.advice_contexts.advice_id -- LEFT OUTER JOIN common.advising_algorithm_varieties ON common.advising_algorithm_varieties.id = technological_section_1.advice_contexts.advising_algorithm_variety_id LEFT OUTER JOIN technological_section_1.advice_events ON technological_section_1.advices.id = technological_section_1.advice_events.advice_id LEFT OUTER JOIN technological_section_1.events ON technological_section_1.events.id = technological_section_1.advice_events.event_id LEFT OUTER JOIN common.event_varieties ON common.event_varieties.id = technological_section_1.events.variety_id WHERE technological_section_1.advices.dt >= '2023-05-05 00:00:00' AND technological_section_1.advices.dt <= '2023-05-06 00:00:00' AND technological_section_1.advices.purpose_variety_id = 1 AND technological_section_1.advice_reactions.variety_id = 1 AND technological_section_1.advice_contexts.advising_algorithm_variety_id = 1 AND technological_section_1.advices.with_recommendations = true

Ручей Виноградов
SELECT count(DISTINCT technological_section_1.advi...

вон from видишь =) его и передавай в select_from

Ручей-Виноградов Автор вопроса
Tishka17
вон from видишь =) его и передавай в select_from

query = ( select(func.count()).select_from( select(distinct(Advice.id)) .where(and_(*filters_to_apply)) .outerjoin(AdvicePurposeVariety) .outerjoin(AdviceReaction) .outerjoin(AdviceReactionVariety) .outerjoin(AdviceContext) .outerjoin(AdvicingAlgorithmVariety) .outerjoin(AdviceEvent) .outerjoin(Event) .outerjoin(EventVariety) ) ) Вот как надо, т.е. в селект вставить distinct(Advice.id)

Ручей Виноградов
query = ( select(func.count())...

это работает несколько не так как исходный запрос

Ручей-Виноградов Автор вопроса
Tishka17
это работает несколько не так как исходный запрос

это создаёт вот такой запрос SELECT count(*) AS count_1 FROM ( SELECT DISTINCT technological_section_1.advices.id AS anon_2 FROM technological_section_1.advices LEFT OUTER JOIN common.advice_purpose_varieties ON common.advice_purpose_varieties.id = technological_section_1.advices.purpose_variety_id LEFT OUTER JOIN technological_section_1.advice_reactions ON technological_section_1.advices.id = technological_section_1.advice_reactions.advice_id LEFT OUTER JOIN common.advice_reaction_varieties ON common.advice_reaction_varieties.id = technological_section_1.advice_reactions.variety_id LEFT OUTER JOIN technological_section_1.advice_contexts ON technological_section_1.advices.id = technological_section_1.advice_contexts.advice_id LEFT OUTER JOIN common.advising_algorithm_varieties ON common.advising_algorithm_varieties.id = technological_section_1.advice_contexts.advising_algorithm_variety_id LEFT OUTER JOIN technological_section_1.advice_events ON technological_section_1.advices.id = technological_section_1.advice_events.advice_id LEFT OUTER JOIN technological_section_1.events ON technological_section_1.events.id = technological_section_1.advice_events.event_id LEFT OUTER JOIN common.event_varieties ON common.event_varieties.id = technological_section_1.events.variety_id ) AS anon_1

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Anyone else having this error when trying to make transactions?
Datzel
11
Question: How viable is it to use Anvil as the backend infrastructure for managing a TradFi portfolio, while integrating Flexa for instant liquidity and payment solutions? Cou...
Kevin
2
вы делали что-то подобное и как? может есть либы готовые? увидел картинку нокода, где всё линиями соединено и стало интересно попробовать то же в ddl на lua сделать. решил с ч...
Victor
8
Карта сайта