Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Structured Query Language is a language for interacting with relational databases. Read the tag wiki's guidelines for requesting SQL reviews: 1) Provide context, 2) Include the schema, 3) If asking about performance, include indexes and the output of EXPLAIN SELECT.

1
vote
0answers
23 views

Calculate NPS in a stored procedure

We collect customer surveys and one of the questions is the dreaded "How likely are you to recommend our service?" question from which we calculate a Net Promoter Score. (I hate this calculation, but ...
0
votes
0answers
40 views

SQL Query to get parent parts of materials using Recursive CTE

The intent of the query is to filter out certain materials to get to a list that will then be run through a recursive CTE to drill up through the BOM to the 0 level assembly. P_Parts_CTE is filtering ...
-2
votes
0answers
19 views

Insert dataframe to SQL database [on hold]

I am trying to insert the Dataframe which looks like this ...
2
votes
0answers
26 views

SQL/PHP Laravel - Looping through records to find relationships

I have two tables in my database, which contains a big list of organisations. They are called orgs_main and orgs_sub. This is ...
4
votes
1answer
59 views

Retrieving a product's sold quantity

I've written a view to retrieve each product's sold quantity and four week sales average by Branch/Route/...
2
votes
0answers
29 views

Stored procedure to implement a search filter

I've implemented a stored procedure for a search process SQL Server 2008. I'm not sure if everything I created is correct. Also I'm wondering if this code has any leaks or vulnerability on SQL ...
-3
votes
1answer
44 views

3 tables in SQL [closed]

Lets say i have 3 tables: users, posts and comments. ...
5
votes
2answers
62 views

Find how much reputation a user had on a given date

I saw this question on MSE and went ahead and wrote a solution to it: https://meta.stackexchange.com/questions/313561/determining-users-reputation-as-of-particular-date This calculates the ...
0
votes
1answer
24 views

Worst Query performance issue on date calculation

I have a stored procedure that is taking more than 2 hours to complete and I noticed the below SQL is taking close to 25 mins for updating a million+ values.There are multiple steps like this and all ...
2
votes
1answer
29 views

Query to find instances of two types of events occurring more than one second apart

I have 3 tables on my database: BusinessObject and CustomEvent, and EventType. ...
3
votes
1answer
31 views

Stored procedure for sending emails at specified times after license expiration

I need to send email notifications for expired licenses: One Day Before/After Expiration Two Days Before/After Expiration Three Days Before/After Expiration One Week Before/After Expiration Two Weeks ...
2
votes
0answers
42 views

Calculating effective shop inventories (SQL)

This is an SQL version of that question. Shops and groups The problem domain is a collection of shops (identified by an int shop_id number) each of which is ...
1
vote
3answers
53 views

Login module with JDBC

I made simple login module that is responsible for handling registration, and signing in my application. How can I improve this code? Are there any conventions for this case? The idea is to create ...
1
vote
1answer
107 views

Basic object-oriented PHP login, logout, and registration scripts

I am new to OOP in general and have recently started trying to develop object-oriented PHP code instead of relying on a primarily procedural style, as this is a requirement for my studies. One part of ...
1
vote
1answer
93 views

PDO Dynamic query builder

I'm trying to improve my php oop programming skills. As an exercise I wrote this class that will generate and execute dynamic sql queries. I've also writed a class to call various sanitization filters ...
0
votes
0answers
20 views

Querying 2 or more tables with joins or eloquent relations

I have few tables that store the details of educational content within a school. Tables' descriptions viz. A grades table stores all grades, subject table stores all subjects, ...
1
vote
1answer
45 views

HTML file with a submit form

I have an HTML file that contains a submit form, which asks the users the fill in their personal info: then it will post and store into the DB by method of PHP SQL: ...
0
votes
0answers
12 views

Filtering query by date built from integers - how to make more readable

I am trying to make stored procedure and pass some parameters for filtering. As soon as filtering is in horizon, code has to be as generic as possible with less as possible if else etc. How could I ...
4
votes
2answers
28 views

Select recordIDs for Bill of Materials

I have a hierarchy of parts in my database. For example, one part (call it 0010102-0112-315) is a resistor. It's used in a billion different top-level assemblies. ...
-1
votes
2answers
99 views

MySQL select between MAX-n1 AND MAX-n2

I just made this link please check this out Online Results I need to select data between 2 values from a table by using MAX because each SID has different VID. My code: ...
7
votes
0answers
62 views

Science Fiction Wall of Fame (Shame?)

I have a few of hobbies, one is reading science fiction and fantasy and another is coding solutions. I thought I might have a chance to combine both hobbies on this project. I have well over 1500 ...
1
vote
0answers
36 views

Oracle SQL Code - Multiple Joins used

I'm currently working on some SQL code within Oracle Fusion BIP but it's not very optimised as it's using multiple LEFT,RIGHT and FULL OUTER joins to link tables together. Unfortunately this is ...
3
votes
0answers
25 views

Reading Database, scraping Barchart and uploading prices to DB

This is my first real excursion into Python, coming from C#. I wanted to see if my code is well-formatted and efficient. The following will read the needed codes from a Database Table, then submit ...
0
votes
0answers
27 views

Nested SQL-query with table-scan performance

I have made a stored procedure, that takes a list of keywords and inserts the one that doesn't exist in a table. After reviewing the execution plan I fear, that the procedure will become slow as the ...
2
votes
1answer
31 views

Getting marks without getting personal

We've tables adm_app, quals_data to which personal_data is a parent table. We are retrieving ...
5
votes
0answers
69 views

Modeling tabular structure in MSSQL to store data like Excel sheet applying Column inheritance

I've created this database structure to store tabular information (it's a simplification of my real structure but enough to show the point). In it I have Sheets and ...
0
votes
1answer
56 views

Optimize code for sending collected data to a database

I'm sending some data over to a database. There is a particular part that requires me to send a bunch of stuff all at once. It seems a little silly to me to write it this way. I feel that I could do ...
0
votes
0answers
45 views

PHP SQL Select statements

...
4
votes
0answers
38 views

Insert a page definition in the right order

I have a table SlideList that defines all available slides that can be put into a PowerPoint presentation. I have a table ...
1
vote
1answer
28 views

Query for customer quotes by date range

I have a table (Oracle): customer_quote ------ int id int part_key (fk) int condition_code (fk) number unit_price int qty_quoted date entry_date With a query ...
1
vote
0answers
146 views

Design database for OHLC

Requirements: I have to design a database to store tick data of 350 stocks. Inside this database queries will be executed to transform tick data and retrieve OHLC candles of 1 minute, 1 hour, 1 day. ...
2
votes
0answers
34 views

Counting distinct number of items in multiple group by query efficiently

I have the following query that counts the number of vessels in each zone for each week: ...
2
votes
0answers
72 views

PostgreSQL: maintaining non-overlapping temporal ranges

I have to store some temporal meta data used primarily in bulk processing of a time-series (sensor measurements). Each value of this meta data is valid for a potentially half-open range of time. ...
1
vote
1answer
32 views

Simple script to insert data

This is a simple script which inserts data into a couple of tables. I'm very new to SQL so any feeback, of any kind, would be much appreciated! ...
0
votes
0answers
68 views

Optimizing (combining?) similar select queries

I have a table: ...
1
vote
1answer
37 views

Ledger query using window functions

This is a ledger kind of table, initial amount is when the movement is null and all transactions on it is based on the Waste_Seq the query take the last entry (id) based on the movement and change ...
2
votes
0answers
35 views

Breaking down retention metrics

Does this code calculate the retention rate per acquisition channel correctly? $$ R = \frac{E - N}{S} * 100 $$ Where \$E\$ is the number of customer at the end of a period, \$N\$ is the number of ...
0
votes
0answers
39 views

Method to store X509 certificate from Database

I've a method that gets certificate as BLOB and password as char[] from Oracle Database, store this certificate x509, trust it, get the secure connection and verify ...
4
votes
1answer
46 views

Stack Overflow Tag Usage

I am trying to efficiently use the SEDE tool to get a list of tags a user has answered questions on, and their stats on each Tag. My code works for my account in 3185 ms, but if I try to run it on @...
5
votes
2answers
92 views

Combining SQL Tables into One Table in New DB with Similar Fields

I have a SQL Server Database filled with Reports all having the same schema. What I've done is created a .NET application to automate the process of adding all reports to a new table. How can the ...
3
votes
1answer
108 views

SQL QueryBuilder

I've made a simple querybuilder for my job, but I'm kind of insecure about starting to use it because I'm afraid of errors happening when I start using it. I've done some tests with ...
1
vote
2answers
60 views

Merge table stored procedure

I wrote a stored procedure that will do a merge of two tables: ...
2
votes
1answer
48 views

Database model for a hotel

I have to create a Hotel database according to these requirements: information about guests should be found, information about rooms divided into categories, reservations (ordered by a type of a room ...
4
votes
0answers
169 views

Fastest way to insert rows in mysql vs sqlserver (large dataset)

I'm looking for any possible improvements that could be made to run the mysql piece of code faster. I created a simple test winform application that creates two docker databases : Sqlserver on linux ...
5
votes
2answers
395 views

Searching for a word in a list of tuple extracted from a db via SQL

Python 3.6 and Sqlite3. I have a database with something like 300K entries, each entry has several fields (date, username, etc) and a "text" one. I have a list of 200 words and for each word i have ...
3
votes
2answers
126 views

Secure PHP login with SQL injection prevention

I am working on a project where users have to log in then if it is correct it creates a cookie to process requests. I would like to find a way to auto-renew sessions every day without affecting the ...
3
votes
2answers
76 views

SQL Server - Iterate, aggregate, and insert

I'm trying to find an efficient way to aggregate data for reporting. Let's say I need to aggregate the following data in 5-second intervals: ...
2
votes
1answer
41 views

Comparing data in SQL using foreign keys

The following is given: ...
4
votes
1answer
30 views

Parse numbers from text based on relative position to certain substrings

The input is a product code. I want to pull out the "percentage" portion of that code. For example, if the code contains the substring BIO, I want all the numbers that follow it until I hit another ...