Hello i need to run a query with 2 select statements, one with an avg calculation and grouped by name and the other select, looking for that name in other table, and get some columns and do a JOIN to merge both and only left one column "name" on it.
The first table its this:
+------+-------------+-----------+-----------+
| Name | Time | LowPrice | HighPrice |
+------+-------------+-----------+-----------+
| #AAA | 12/13/2021 | 383.12 | 393.9 |
| #BBB | 12/13/2021 | 1110.34 | 1114.1 |
+------+-------------+-----------+-----------+
The second table its like this:
+------+-------+----------+
| Name | digit | currency |
+------+-------+----------+
| #AAA | 2 | USD |
| #BBB | 1 | EUR |
+------+-------+----------+
The final query should return something like this:
+------+-------------+-----------+-----------+-------+----------+
| Name | Time | LowPrice | HighPrice | digit | currency |
+------+-------------+-----------+-----------+-------+----------+
| #AAA | 12/13/2021 | 383.12 | 393.9 | 2 | USD |
| #BBB | 12/13/2021 | 1110.34 | 1114.1 | 1 | EUR |
+------+-------------+-----------+-----------+-------+----------+
I know this query should be something like this:
SELECT *
FROM (
SELECT name, date_trunc('day', "Time"), avg("LowPrice"), avg("HighPrice")
FROM sometable
GROUP BY "name", date_trunc('day', "Time"
) t
CROSS JOIN (
SELECT name, digit, currrency
FROM othertable
GROUP BY "name"
) m
but doesnt work, thanks for your heads up and help me to debug this