I have a SQL database with a list of Customer IDs CustomerID and invoices, the specific product purchased in each invoice ProductID, the Date and the Income of each invoice . I need to write a query that will retrieve for each product, which was the second customer who made a purchase How do I do that? EDIT: …
Tag: sql
MS Access SQL: Sum IIF for multiple Criteria, Format as Column instead of Row
I’m working in MS Access 365 and I have a table containing multiple status that I want to summarize in a Pie Chart. Sample Data: Sales Order# Status 1 New 2 Pending 3 Closed The Statuses are defined by human readable text in a separate table, but are linked in the master table before I run the query. I …
SQL – Sum of specific column grouped by a specific value of another column
I have a SQL with list of Customer IDs and invoices, the specific product purchased in each invoice, and the income of each invoice. I need to write a query that will result in a list of customer IDs in one column, and the sum of total income from purchasing “product A”, by each customer, in anoth…
How create table with name which name in another table
There is a table in which all the names of the tables are located and I need to create a table with a name from it. I give id to the input of the stored procedure and by this number I need to pull the name from another table result some I need create database schema3.Users. And this table must
Postgresql: Get columns of other table as array in a object as a column with condition
i have 2 tables, servers and virtual_machines. I want to see the virtual_machines as array in the servers where serverName equals the servers name Like this I have servers tables and virtual_machines tables I tried many options like bellow but i cant make object array in colum and postgre always add key into …
SQL – Return “True” if a customer purchased product A, and “False” otherwise [closed]
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 simple SQL table with a list of customer IDs, Invoices, Products they have purchased …
Escaped single quote ignored in SELECT clause
Not sure why the escaped single quote doesn’t appear in the SQL output. Initially tried this in Jupyter notebook, but reproduced it in PySpark shell below. Output shows Bobs home instead of Bob’s home Answer Use backslash instead of a single quote to escape a single quote: Alternatively, you can u…
How to select data using like with out consider after character in laravel or sql
I have a table call labels_table. id label 1 A_1_1 2 A_1_2 3 A_2_1 4 A_4_1 5 A_10_1 6 A_11_1 I need to select all the labels for A_1 group. A_1_1 and A_1_2 should be the correct labels. I used the following query. sql Larval But both SQL and laravel queries returns all A_1_1, A_1_2, A_10_1 and A_11_1. But I
Sql Performance join Vs co-related Subquery
TABLE : employee (id,mid,join_date) Question – Find all employees who joined before their managers Query 1: Query 2: Which of them is correct? If both correct, then how is the performance? Answer They are both correct. Performance questions need to be tested on your data on your system. However, with a …
How to get percentage between number of rows in two separate databases?
I have two databases (A and B). I need to find the percentage between number of **rows in A** and number of **rows in B** (for example, if I have *100 rows in A* and *10 in B*, *result will be 10%*). Is there a way to do so using **JOIN** operator? I tried with “**SELECT COUNT(*) FROM DBA**” to