SUM OVER PARTITION BY

In my opinion, I think it’s important to explain the why behind the need for a GROUP BY in your SQL when summing with OVER() clause and why you are getting repeated lines of data when you are expecting one row per BrandID. Take this example: You need to aggregate the total sale price of … Read more

JPA find the Last entry

The results of query methods can be limited via the keywords first or top, which can be used interchangeably. An optional numeric value can be appended to top/first to specify the maximum result size to be returned. If the number is left out, a result size of 1 is assumed. JpaClass findFirstByOrderByIdDesc(); referenced by Spring … Read more

What is wrong with this code. Why can’t I use SqlConnection?

If you just updated EntityFrameworkCore from version 2.x to 3.x and you’re running into this, change your using statement to Microsoft.Data.SqlClient instead of System.Data.SqlClient. If you’re using EntityFrameworkCore.SqlServer it already has that as a dependency, so you shouldn’t need to install it explicitly. This Microsoft blog explains the change. The Microsoft.Data.SqlClient package, … , will … Read more

PostgreSQL column type conversion from bigint to bigserial

As explained in the documentation, SERIAL is not a datatype, but a shortcut for a collection of other commands. So while you can’t change it simply by altering the type, you can achieve the same effect by running these other commands yourself: CREATE SEQUENCE temp_id_seq; ALTER TABLE temp ALTER COLUMN id SET NOT NULL; ALTER … Read more

How to add parameter values to pgadmin sql query?

I only know two ways. First is to use PREPARED STATEMENT (Example after PostgreSQL Manual): PREPARE usrrptplan (int) AS SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid AND l.date = $2; EXECUTE usrrptplan(1, current_date); PREPARE creates a prepared statement. When the PREPARE statement is executed, the specified statement is parsed, analyzed, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)