[Solved] Ascending or descending list...

Discuss the database features
Post Reply
Nick N,
Posts: 140
Joined: Wed Aug 09, 2023 2:10 pm

[Solved] Ascending or descending list...

Post by Nick N, »

Hello,

I'd like to submit to your attention 2 subsequent queries.
I tried this:

Code: Select all

SELECT "Products"."brand", "Story"."date of purchase", YEAR( "date of purchase" ) AS "years", MONTH( "date of purchase" ) AS "months" FROM "Story", "Products" WHERE "Story"."ID_product" = "Products"."ID_product" ORDER BY "years", "months" ASC
Can anyone show me an alternative way to obtain an ascending list?

Thanks

Nick
Attachments
draft 1.png
draft 1.png (33.5 KiB) Viewed 3441 times
draft 2.png
draft 2.png (11.13 KiB) Viewed 3441 times
Purchasing.odb
(13.59 KiB) Downloaded 183 times
Last edited by Nick N, on Sat Oct 21, 2023 5:08 am, edited 1 time in total.
Libre Office 6.0.7 on Ubuntu 18.04
User avatar
robleyd
Moderator
Posts: 5087
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Ascending or descending list...

Post by robleyd »

Did you try ORDER BY"date of purchase"? Assuming that is a date field.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Ascending or descending list...

Post by UnklDonald418 »

to cover multiple items with the same purchase date

Code: Select all

ORDER BY "Story"."date of purchase", "Products"."brand" ASC
or maybe

Code: Select all

ORDER BY "Story"."date of purchase",  "Products"."unit price" ASC
or list most expensive items first

Code: Select all

ORDER BY "Story"."date of purchase" ASC,  "Products"."unit price" DESC
Using non-printing characters in field names can come back to bite you. If you don't like run on names like "dateofpurchase" use "date_of_purchase" or "date-of-purchase". When writing queries, abbreviated names are easier to type like "upr" and "dop".
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Nick N,
Posts: 140
Joined: Wed Aug 09, 2023 2:10 pm

Re: Ascending or descending list...

Post by Nick N, »

Thank you for having replied quickly.
Regards
Nick
Libre Office 6.0.7 on Ubuntu 18.04
Post Reply