Doctrine DQL random row? - doctrine-orm

I am trying to get a random row from my table. I found this SQL example:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
Is it possible to do it in pure DQL ?

Related

PowerBI concatatenate 3 tables

I'm trying to concatenate 3 different tables in powerBI, with powerQuery but I couldn't find the solution for it. The closest I could find is appending the query, however it does not concatenate the table shown below.
Example:
Im trying to concatenate table Code1 to Code2 to Code3 (bottom 3 tables) to look like the top one.
Thank you very much for your help
Alternate method
In Table3, add column, custom column,
= Table1
then expand
Add column, custom column
= Table2
then expand
Add a custom column to each of your queries, all with the same value. For my test I just used the value of 1.
Then merge Query 1 to Query 2 on your custom column. Next, merge that query to Query 3 again on the custom column. Once you rearrange the columns you will get an output that looks like this:

Retrieving the row with the greatest timestamp in questDB

I'm currently running QuestDB 6.1.2 on linux. How do I get the row with maximum value from a table? I have tried the following on a test table with around 5 million rows:
select * from table where cast(timestamp as symbol) in (select cast(max(timestamp) as symbol) from table );
select * from table inner join (select max(timestamp) mm from table ) on timestamp >= mm
select * from table where timestamp = max(timestamp)
select * from table where timestamp = (select max(timestamp) from table )
where 1 is correct but runs in ~5s, 2 is correct and runs in ~500ms but looks unnecessarily verbose for a query, 3 compiles but returns an empty table, and 4 is incorrect syntax although that's how sql usually does it
select * from table limit -1 works. QuestDB returns rows sorted by timestamp as default, and limit -1 takes the last row, which happens to be the row with the greatest timestamp. To be explicit about ordering by timestamp, select * from table order by timestamp limit -1 could be used instead. This query runs in around 300-400ms on the same table.
As a side note, the third query using timestamp=max(timestamp) doesn't work yet since QuestDB does not support subqueries in where yet (questDB 6.1.2).

How to only show TOP N in table

I have a simple table with a name field and a count(distinct) field and I am trying to figure out how to show only the TOP N records based on the count(distinct) column, the sorting and the count works great I just cannot find the option to limit it to top N records
The solutions I know are:
Use RANK calculation, then inserting a filter
Create a new table in dax using the TOPN function
https://dax.guide/topn/
NewTable = TOPN(100, YourTable
, YourTable[ColumnToOrder]
, DESC)

Calculated Column to get average from values in another table in PowerBI

This might be very basic but I am new to PowerBI.
How do I get average of values for unique ID into another table.
For eg. My Table 1 has multiple ID values. I have created another table for unique ID which I am planning to used to join other table.
I want a calculated column in table 2 which will give me average value of respective ID from table 1.
How do I get the calculated column like shown below
In stead of creating a new table with the averages per ID and then joining on that, you could also do it directly with a calculated column using the following DAX expression:
Average by ID = CALCULATE(AVERAGE('Table 1'[Values]),ALLEXCEPT('Table 1','Table 1'[ID]))
Not exactly what you asked for, but maybe it's useful anyway.
How's it going?
The quickest way I can think of doing this would be to use
SUMMARIZECOLUMNS
You can accomplish this by creating another table based on your initial fact table like so:
Table 2 =
SUMMARIZECOLUMNS ( 'Table 1'[ID], "Avg", AVERAGE ( 'Table 1'[Values] ) )
Once this table has been created, you can create a relationship.
This will work in either SSAS or in PowerBI directly.
Hope this helps!! Have a good one!!

How do I select rows from an Sqlite table exluding ones from a previous query?

I have an Sqlite table having > 25 million rows. I'd selected 1 million rows randomly from this table using the following code:
# using sqlite3 code
c = cursor.execute("SELECT *
FROM reviews_table WHERE ROWID IN (SELECT ROWID FROM reviews_table ORDER BY RANDOM() LIMIT 1000000) ")
Now, I wish to select another 1 million rows from the table, excluding those rows in the previous query. How would I go about doing this?