I have 5 tables: Table Reports Many to many table ReportsIpRel Table of InfoProviders Many to many table QueriesIpRel And table of Queries The SELECT I am trying to achieve is the following: I tried many left/inner joins like this: but all for nothing. I have to use where condition: WHERE report_Id = ‘2…
Create aggregated SQL report where the columns are based on a table list
Not sure this is possible but I’m hoping someone can point me in the right direction. I have a database that audit logs when a record changes stage. What I need to do is consolidate this back up into a report that gives me the earliest audit record for each stage by Record ID. i.e. I end up with a
Select last N rows with multiple values in a single query
I have a table: messages: < id – title – body – city – street – building – created on > While I was able to select required messages in multiple queries, I need to do it in a single one: Here are my queries at the moment: I need one query because I can then use ORDER …
using ORDER BY in SQL for chunks of data
I want to know how I sort data in a SQL query but only in certain chunks. I’ll provide an example to make it easier. In the above example, I want to do an ORDER BY height DESC, BUT only the tallest person of each rank gets ordered and everyone else in the same rank is right under that person
Postgresql select distinct Column A based on certain conditions on Column B
I have a table with data: I would like my query output to be distinct on userid but with condition that between fail and success values in status column. I would like to choose success instead (if both fail as in user_3, choose fail then). The table below shows the output that I would like to have as my resul…
which is better for user activity in laravel database or log file [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago. Improve this question hi im thinking about user activity in laravel application .. and i th…
How to avoid MySQL composite primary key permutations?
CREATE TABLE Friends_Relations( buddy_id VARCHAR(255) NOT NULL, mate_id VARCHAR(255) NOT NULL, PRIMARY KEY (buddy_id, mate_id), FOREIGN KEY (buddy_id) REFERENCES Users(id) ON DELETE …
Anyway to add a constraint when using SQL count
I want to to use count to include a criteria where patient doesn’t have diabetetes, and then using the query to show country that has at least 3 patients that doesn’t have diabetes How shoudl I be doing this? How can I include a constraint when using count? yeah I think this should work, basically…
sql: long to wide format without using PIVOT
I have a table like the following: I want to convert the data to wide format like the following: the SQL I used does not have a pivot choice so I am wondering how to convert the long format to wide without using PIVOT. Answer If I understand your question correctly, you can do conditional aggregation: Maybe y…
Variables in SQLITE Python
I am working in Jupyter Notebooks using pandasql, which uses SQLight syntax. I am trying to select entries from a certain month, depending on a variable. I am planning to create a Python function that will change the value of the variable being used, but right now I am trying to get “Parameterized Queri…