Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question I Have a database of published website pages, with following coulmns: date| publisher_id | pla…
Tag: sql
MySQL never completes query with a subquery, but completes when queries are run separately
This is the query that never finishes: When I run just the subquery, it completes in 12ms and returns two ids. When I hardcode those 2 ids in place of the subquery, the outerquery returns two rows and completes in 0.3ms. As you can see, both parts of the query run incredibly quickly and it’s not like we…
Snowflake: SQL Query to identify all the different users with the same ID from the same or multiple tables
There are two tables with both IDs and Usernames. Looking for a snowflake SQL query that results in identifying the IDs shared by different users from the same table or both tables. Table 1 ID User 1001 A 1002 B 1003 C 1002 D 1005 E Table 2 ID User 1006 H 1005 E 1003 G 1002 F 1001 A
How to count the number of entries in the list when requesting Select?
I apologize for the possible incorrectness in the presentation, I use a translator. Let’s say there is a users table in which there is an id field. And there is a list that lists the id numbers and some of them are repeated. My query returns the following 3 – 1, 10 – 1. And I would like to g…
SQL query counting stats – counting if this is the first record in a table for a particular user
I’m building some basic stats/reporting into a CRM system built in php/mysql. Consider the query: This is working so far to return the desired statistics but I am struggling for the best way to identify new students. For the purposes of this report a new student would be any user_id for whom the current…
SUM aggregation do not work on empty subqueries with DRUID
Assuming I am executing the following two queries on Druid: I tried to combine both counts in one single query with a sum aggregation like the following: And it works well UNLESS one of the two counts returns 0 rows. In that case I receive a Query returned no data message and I don’t have any final resu…
Date range to row in postgres
I have a table in postgres like this: id open_date close_date 5 2006-08-04 2019-12-31 There exist 4897 days between them. I need to turn the date range to date to have one record per day. For example: id open_date close_date valid_date 5 2006-08-04 2019-12-31 2006-08-04 5 2006-08-04 2019-12-31 2006-08-05 5 20…
PostgreSQL – how to have the 0 values using a WHERE?
i am currently working on PostgreSQL having 2 data tables : item and order. I want to display the number of order for each item in a period of time, but i would like to keep the name displayed if it’s 0. i’m actually doing: The problem is that my results are: And i would like to have: I have
Implement batchMerge() in JOOQ
I need to “upsert” a List of items. If an item’s id and anotherId is already existing, other values should be replaced by the new item. If it’s not, item should be inserted as new record. I came across JOOQ’s batchMerge and I thought it is similar to “upsert”. Unfortu…
Check if procedure exists in any database SQL Server
I’d like to know if there is any way to search for a procedure in all the databases of a server (there are only SQL Server databases on that server). So far I’ve only found how to find a stored procedure in a certain database with Object_id(), but it would take too long for me to manually search e…