Skip to content
Advertisement

Tag: sql

Sum unequal and removing duplicates from SQL query results

My base query: It can get me these outputs: Output example: Obs: There is a constraint on (id, on_date) meaning there can always be only one record of a project production on a specific date. Duplicate records, that have the same id, and exist in both dates and have different production values (wanted) Single records, that exists on only one

trying to select random data PostgreSQL

I’m trying to select random strings. The problem is it returns the same value for each row. Why is that and how to fix? 10 rows Answer Postgres overoptimizes the subquery. I think this is an error, because it is missing the fact that random() is volatile. A simple fix is a correlation clause: I rewrote the logic a bit,

How to update multiple records in Codeigniter

In above code snippet first function is declared in controller and second function is declared in model. I want to update owner for multiple rows having ids in $astrep. Can anyone please help me? Answer You can use whereIn() or orWhereIn() methods from query builder class. Refer https://codeigniter4.github.io/userguide/database/query_builder.html#looking-for-specific-data

Case when date = current_date then text

I have a table like this: But when I execute this query: I get this result: SQL Fiddle I would expect that in the rows where is_equal is true, the result should be TODAY. What am I doing wrong? Answer Nevermind, I solved it, but I don’t want to discard the question. The solution is to CAST(token_date as varchar) in

Advertisement