Skip to content

Commit 9c6afcd

Browse files
committed
fix: reverse date simply
1 parent cc67916 commit 9c6afcd

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

live-demo/app/index.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,34 +148,30 @@ if (import.meta.url === `file://${process.argv[1]}`) {
148148
const db = admin.resource('aparts').dataConnector.client;
149149
const days = req.body.days || 7;
150150
const apartsByDays = await db.prepare(
151-
`SELECT * FROM (
152-
SELECT
151+
`SELECT
153152
strftime('%Y-%m-%d', created_at) as day,
154153
COUNT(*) as count
155154
FROM apartments
156155
GROUP BY day
157-
ORDER BY day DESC
158-
LIMIT ?
159-
) ORDER BY day ASC`
156+
ORDER BY day ASC
157+
LIMIT ?;`
160158
).all(days);
161159

162160

163161
const totalAparts = apartsByDays.reduce((acc: number, { count }: { count:number }) => acc + count, 0);
164162

165163
// add listed, unlisted, listedPrice, unlistedPrice
166164
const listedVsUnlistedByDays = await db.prepare(
167-
`SELECT * FROM (
168-
SELECT
165+
`SELECT
169166
strftime('%Y-%m-%d', created_at) as day,
170167
SUM(listed) as listed,
171168
COUNT(*) - SUM(listed) as unlisted,
172169
SUM(listed * price) as listedPrice,
173170
SUM((1 - listed) * price) as unlistedPrice
174171
FROM apartments
175172
GROUP BY day
176-
ORDER BY day DESC
177-
LIMIT ?
178-
) ORDER BY day ASC`
173+
ORDER BY day ASC
174+
LIMIT ?;`
179175
).all(days);
180176

181177

@@ -208,16 +204,14 @@ if (import.meta.url === `file://${process.argv[1]}`) {
208204
).get();
209205

210206
const listedVsUnlistedPriceByDays = await db.prepare(
211-
`SELECT * FROM (
212-
SELECT
207+
`SELECT
213208
strftime('%Y-%m-%d', created_at) as day,
214209
SUM(listed * price) as listedPrice,
215210
SUM((1 - listed) * price) as unlistedPrice
216211
FROM apartments
217212
GROUP BY day
218-
ORDER BY day DESC
219-
LIMIT ?
220-
) ORDER BY day ASC`
213+
ORDER BY day ASC
214+
LIMIT ?;`
221215
).all(days);
222216

223217

0 commit comments

Comments
 (0)