add new AllServiceStatistics query

This commit is contained in:
Pavel 2024-03-25 11:30:06 +03:00
parent 95a2f52339
commit bec22dd0b5
2 changed files with 33 additions and 1 deletions

@ -610,4 +610,25 @@ WHERE
question.quiz_id = $1 AND deleted = false;
-- name: GetQidOwner :one
SELECT accountid FROM quiz where qid=$1;
SELECT accountid FROM quiz where qid=$1;
-- name: AllServiceStatistics :one
WITH Registrations AS (
SELECT COUNT(*) AS registration_count
FROM account
WHERE created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
),
Quizes AS (
SELECT COUNT(*) AS quiz_count
FROM quiz
WHERE deleted = false AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
),
Results AS (
SELECT COUNT(*) AS result_count
FROM answer
WHERE result = true AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
)
SELECT
(SELECT registration_count FROM Registrations) AS registrations,
(SELECT quiz_count FROM Quizes) AS quizes,
(SELECT result_count FROM Results) AS results;

@ -145,3 +145,14 @@ func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req D
return resp, nil
}
type StatisticResp struct {
// от from до to
Registrations uint64 // количество зарегестрированных аккаунтов
Quizes uint64 // количество созданных не удаленных квизов
Results uint64 // количество ответов с result = true
}
func (r *StatisticsRepository) AllServiceStatistics(ctx context.Context, from, to uint64) (StatisticResp, error) {
allSvcStats, err := r.queries.AllServiceStatistics
}