Composite multiple query results

I asked this question a few days ago about how to retrieve journal 7 days ago.
I have a follow up question, what if I would like to retrieve journals 7 days ago, as well as 30 days ago (a month) and 365 days ago?
I certainly can have three individual queries but I wonder if there is a cleaner method.
Also, my current query is

{                                                                                                                                                                                                                 
    :title            "⑦ 一星期前"                                                                                                                                                                                   
    :query            [:find ?name                                                                                                                                                                                   
                       :in $ ?span                                                                                                                                                                                   
                       :where                                                                                                                                                                                        
                       [?p :block/journal? true]                                                                                                                                                                     
                       [?p :block/journal-day ?span]                                                                                                                                                                 
                       [?p :block/name ?name]                                                                                                                                                                        
                       ]                                                                                                                                                                                             
    :inputs           [:7d-before ]                                                                                                                                                                                  
    :view (fn [result]                                                                                                                                                                                               
       [:div.flex.flex-col                                                                                                                                                                                           
        (for [page result]                                                                                                                                                                                           
          [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)]                                                                                                                                         
       )]                                                                                                                                                                                                            
    )                                                                                                                                                                                                                
   :collapsed?       false}

and it renders as this
image
I’d like to have three such hyperlinks and ideally a text next to the link showing it’s 7 days, 30 days or 365 days.
Is it possible? Thank you for the help!

How about this?

#+BEGIN_QUERY
{:title "Some days ago"
 :query [:find ?name
         :in $ ?w ?m ?y
         :where
         [?p :block/name ?name]
         [?p :block/journal? true]
         (or [?p :block/journal-day ?w]
             [?p :block/journal-day ?m]
             [?p :block/journal-day ?y])]
 :inputs [:7d-before :30d-before :365d-before]
 :view (fn [result]
         [:div.flex.flex-col
          (let [days ["7 days ago" "30 days ago" "365 days ago"]]
            (map (fn [page day]
                   [:a {:href (str "#/page/" page)} (clojure.string/capitalize (str page " (" day ")"))])
                 result days))]) 
}
#+END_QUERY

EDIT: Found one problem with this query. If you delete some journal pages, then it will mess up the “days ago” display.

For example, If you delete the page made 30 days ago, then it will display the “365 days ago” page with “30 days ago” text. :frowning_face:
Screenshot from 2022-08-02 21-42-22

1 Like

Thanks!! That’s really clever! Also seems that logseq sort by date by default, but just in case I have another sort-by for sanity check, and my final query is this

#+BEGIN_QUERY
{:title "Some days ago"
 :query [:find ?name
         :in $ ?w ?m ?y
         :where
         [?p :block/name ?name]
         [?p :block/journal? true]
         (or [?p :block/journal-day ?w]
             [?p :block/journal-day ?m]
             [?p :block/journal-day ?y])]
 :inputs [:7d-before :30d-before :365d-before]
:result-transform (fn [result]
    (sort-by (fn [d]  (get d :block/created)) result))
 :view (fn [result]
         [:div.flex.flex-col
          (let [days ["7 days ago" "30 days ago" "365 days ago"]]
            (map (fn [page day]
                   [:a {:href (str "#/page/" page)} (clojure.string/capitalize (str page " (" day ")"))])
                 result days))]) 
}
#+END_QUERY

For the deleted journal, maybe someone else can chime in, but I guess it’s just because of the mismatch of result array (2 elements) and days array. I think this can be solved if we can return two from the query, 1 for page 1 for days. But I couldn’t find a correct way to do this