Skip to content

Tag: postgresql

What am I doing wrong in this where statement?

I’m using the following logic in my where statement. If I do just the statement below then it returns results However if I expand on the where logic to the following statement it returns no results. Why? Shouldn’t it return the same thing as where statement above? Basically what I want is the foll…

Postgres Import from different table

I’m still fairly new to postgres. I have a table named: university_table with fields: name, nationality, abbreviation, adjective, person. I found this sql query to insert data from: https://stackoverflow.com/a/21759321/9469766 Snippet of query below. How can alter the query to insert these values into m…

If statement with select in Postgresql

I’ve having trouble to do a if with select, e.g: In SQL Server I can do this: But in postgresql I don’t have any idea how handle this. I’ve tring some ways to do this, but unfortunately I have not success. Answer The syntax for an IF in Postgres (or rather PL/pgSQL) is IF … THEN &#8230…

Counting users based on an event count

I have an events table where I currently have a count of users grouped by the date. I am wanting to make two different counts based on the number of times a user had a specific event (we’ll call it event_a) The first count will count the user if event_a appeared exactly 1 time for the user, the 2nd coun…

date time comparison with > does not work

I have two SQL statements: 1) (now i use this) 2) (but i need to use this) first query return 11 lines query 2 return 388. my observation (about query 2) is that instead of “2019-11-26 13:20:00” it is taken “2019-11-26” and when I replace it really returns the same answer date_occured …