I tried date format in the where clause it showing me an error.
this is the query im converting
SELECT , (SELECT COUNT() from
daily_check
WHERE (daily_checks
.qid
= question
.id
) AND (daily_check
.is_completed
= 1) AND (DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(daily_check
.date
),'+00:00','+5:30'), '%d-%m-%Y') = '30-07-2023')) AS is_checked
FROM question
WHERE (restaurant_id
=1) AND (status
=1) AND (trash
=0) AND (category
=1) HAVING is_checked
= 0
this is what i converted and having the error
const sq = db
.select({ count: sql<number>count(*)
.mapWith(Number) })
.from(dailyCheck)
.where(
and(
eq(dailyCheck.qid, question.id),
eq(dailyCheck.isCompleted, 1),
eq(sqlDATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(dailyCheck.date), "+00:00", "+2:30"), "%d-%m-%Y")
, "28-07-2023")
)
)
.as("isChecked");
const result = await db
.select({
question: question.question,
isChecked: sq
})
.from(question);0 Replies