Похожие чаты

Подскажите, как тут получить не поля, а количество записей? 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 ответов

43 просмотра

там нужно делать 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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта