Skip to content
Advertisement

GROUP BY within functions

I’m currently stuck with MySQL I would love to make this SQL to use the COUNT for each id_customer that was GROUP BYed as well. Picture of result And now it takes COUNT for every id_customer so it divides everything by 6 instead of 3 for id_customer 3, 2 for id_customer 1 and 1 for id_customer 66. Help would be

How to change arrays into rows

There is a table in BigQuery that contains 2 REPEATED(arrays) type of columns, enterded_date and status. Table in BigQuery: Is it possible to make a query that returns rows instead? Like this: Answer Consider below approach if applied to sample data in your question – output is

How to move ID of duplicate names to a separate column

I have a MySQL table with two duplicate names, how can I separate the IDs of the duplicate names into a separate column? For example, like this: This is my current SQL statement to retrieve the current results in the first table: There is only one duplicate at most for each name. Thanks Answer If you are sure that the

Select from select using Laravel eloquent

I want to get all user’s favourite products. The query should be like this: How can I query with eloquent? Answer You’re trying to achieve something like this: In the oficial documentation you can find the explanation of Advanced where clauses The final result will be (you can see this dumping the query using toSql() method instead of get()) :

update rows using inner join posgresql

I have 2 tables users and countries, and i’m trying to set the country.name with users.country_name for all countries with null name. Schema : Ref: U.country_code > countries.code QUERY Error : DBSQLException: SQL Error [42P01] Answer Follow the correct update join syntax and also remove the alias from the LHS of the SET clause:

Advertisement