Questions tagged [sql]

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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
14 views

Filter filtered bike prices twice without repeating yourself

dbfiddle Goal Without repetition in the code, I want to filter BikeValuationList to only give the BikePriceId of the latest ...
J. Mini's user avatar
  • 127
0 votes
0 answers
10 views

Calendar Table in Power BI

I've been reusing calendar tables in various formats for a few years now. I'd like to know best practices and if there are ways to improve them. Any suggestions for style, code, etc. are all welcome. ...
aduguid's user avatar
  • 490
1 vote
0 answers
73 views

To-do app with TypeScript backend (violations of TS best practices or unidiomatic code)

The working code in full is here. It's a To-Do App with a TypeScript backend, written as practice for an upcoming 4-hour interview for a TypeScript backend role. My colleague and I would like to know, ...
Andrew Cheong's user avatar
2 votes
1 answer
72 views

Need assistance in Optimizing the Recursive Query in Pyspark

I am trying to convert a SQL Server stored procedure to Pyspark code. This is my SQL Server query: ...
Data writer's user avatar
3 votes
1 answer
78 views

Creating an array (temporary table) in SQL and iterating through each row within this table to preform a check on the data in each row

The SQL Server version I am using is SQL Server 2008. I've got an SQL query/script I've written which is to help simplify some things while our API is being rebuilt. Essentially, this script allows ...
level42's user avatar
  • 131
3 votes
2 answers
99 views

Calculate the count of top performers in SQL

I have a transaction table let's call it Offers Table. Please don't read too much into the business but let's say a customer wants to buy a car and the customer searches variety of websites but at the ...
Cody's user avatar
  • 31
6 votes
1 answer
894 views

Show how close a user is to being unsung

So this morning, I decided to create a SEDE query that answers the age-old question "How close am I to being Unsung?" because I recently polished up my first SEDE query and I realized that I ...
CrSb0001's user avatar
  • 257
2 votes
1 answer
33 views

Understanding how to properly create a stored procedure that only does INSERT from sourcetable to targettable with dynamic sql

Background and use-case I need to create a stored procedure where the input parameters will be: @sourceTable, @targetTable, @compositeKey. I'm using available fields for the composite key, since I ...
William's user avatar
  • 21
2 votes
1 answer
242 views

MySQL interval search query suggestions

My database structure is: ...
friday-json's user avatar
1 vote
0 answers
35 views

insert then update generated id back to the table on bulk insert using XML in SQL server

I have 2 tables StockDetails, StockMail First insert Stock name and Expiration Date into StockDetails Table(inserting bulk data using XML) Then Generate Reminder date(7 Days before expiration date) ...
Relax's user avatar
  • 131
2 votes
2 answers
133 views

SQLite querybuilder class in python

Motivated by the first commentor's suggestion on my MSAccess question: Python SQL insert to MSAccess with VBScript I am moving to use SQLite databases for a python application and I created this query ...
spaghetticode's user avatar
3 votes
3 answers
109 views

Improving efficiency of database searches under SQLite (SpatiaLite - QGIS)

I'm new to SQL, but I've always heard that it's a very efficient way of searching databases. For the same task, in VBA I get a result in a few seconds for 1000 queries. In SQL it takes several minutes....
Giene's user avatar
  • 149
4 votes
1 answer
89 views

Python SQL insert to MSAccess with VBScript

I have a business use case that required running SQL insert queries to a local MSAccess database with a Python script. The actual script does many other things and the SQL function is just one of them,...
spaghetticode's user avatar
3 votes
1 answer
91 views

SQL query creating tables needed by a simple PHP CMS

I have written recently the SQL query to MariaDB that I want to move into PHP code. Below is my test.sql file. What do you think about my SQL code? ...
whiteman808's user avatar
0 votes
0 answers
23 views

Prisma models with various relations

The code is a bunch of Prisma models, starting from Move. This model stores data about pokémon moves as can be obtained from the PokéAPI. Further models are shown ...
eloy's user avatar
  • 43
0 votes
1 answer
38 views

Find and conditionally sort all venues matching a filter provided by an API client in PostgreSQL

I have an API where users can retrieve a list of "venues". Every venue is a profile, but not every profile is a venue Venues can be "parents" of other venues (think hotel - floor -...
Felix ZY's user avatar
  • 103
4 votes
2 answers
220 views

Querying for vendors and categories

I'm looking for pointers on the best way to optimize my code below. The query is designed to pull for a vendor database in a separate SQL server table that I built a connection to in my wordpress site....
Mike Mann's user avatar
  • 141
0 votes
1 answer
62 views

Is this PL/SQL Stored proc optimal?

...
Christian Bongiorno's user avatar
2 votes
1 answer
70 views

Find All Recent Winners and Calculate an Encoding of What They Won

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 127
2 votes
2 answers
84 views

Find All Recent Winners and Calculate an Encoding

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 127
0 votes
0 answers
17 views

specify a policy for allowing access to a table through a foreign key

Consider the following two tables in a PostgreSQL database: ...
Nathan Osman's user avatar
1 vote
2 answers
26 views

Creating single table vs creating multiple table

I have lots of services which I am integrating. (also I am new to sql) For each service integration I get different response, For example, for zoom, I would just need to store the access_Token, for ...
iRohitBhatia's user avatar
0 votes
0 answers
18 views

Order Model for a Market Place Ruby on Rails Application

I've created a Marketplace application on ruby on rails and would like to request a review of my code (Order Model) to check if I am in the right track or not...please kindly understand that I am a ...
Panamaniac507's user avatar
1 vote
1 answer
128 views

What is the percentage of customers who increase their closing balance by more than 5%?

The Question What is the percentage of customers who increase their closing balance by more than 5%? Source Code The database and all details can be found here. ERD My Proposed Solution ...
Mike's user avatar
  • 113
0 votes
1 answer
187 views

Optimizing LINQ Query on C# Web API

Can someone help me optimize this code especially the LINQ query. It takes 8-12 seconds just to return a response when I'm calling the endpoint. Its super slow, and my whole endpoint call is taking ...
Kraust123's user avatar
0 votes
1 answer
115 views

Is there a more concise way to write this Procedure

I have this stored Procedure that is passed in the data below that will building the SQL select that will get EXEC. The data that can be passed in can me null so I have three ...
Jefferson's user avatar
  • 359
1 vote
1 answer
70 views

Is there a more concise way to write this query in SQL Server?

I'm playing with data from a Time Use survey as a beginner SQL user. Gender is represented as 1's (Male) and 2's (Female), and the age of each participant is listed. I would like to divide them into ...
Erik's user avatar
  • 303
1 vote
1 answer
335 views

Employee Attendance structure design

I am designing a solution to store employee day attendance, which can be recorded either as hours or as an interval within a day. The goal is to maintain a monthly attendance list for each employee. ...
Andrius's user avatar
  • 119
0 votes
1 answer
29 views

Joining with a different (foreign keys) while using the same key on a different table

I'm a bit new to SQL and I'm still learning how to efficiently use joins. I have two tables. contains Materials and Alternate Materials contains Real_ID and Materials. The code below works however I ...
Milo Sandoval's user avatar
3 votes
0 answers
88 views

Create table of yearly monthly temperatures from monthly data

I've got a series of tables with monthly data on USA regions over about 130 years, divided by either climate divisions (clim_div) or other federal standards (ncdc_fips). They all follow the same ...
DownrightBass's user avatar
-2 votes
1 answer
79 views

Preventing PHP SQL injection on login [closed]

I had a login code like this: ...
Bazim's user avatar
  • 19
1 vote
0 answers
1k views

DB2 SQL statement to split a string based on delimiter

I have a "flat file" with structure as below: ...
Theju112's user avatar
3 votes
1 answer
80 views

calculating the percentage of distribution of ids per Loc for each country

Which of the two queries is theoretically better and why? I would like to understand why query 2 takes longer although there is no relevant information in the Execution Plan. I'm querying a Presto ...
Pin_Eipol's user avatar
1 vote
1 answer
48 views

Find offers that can be matched with bids

I am working on a sql query for the following scenario: Get all available offers for registered demand (offers from profiles should not be from profile which had registered demand). After that get ...
Gleichmut's user avatar
  • 121
0 votes
1 answer
142 views

Count how many active and inactive users are in a group/unit/department/team

Given the following example data: id username group unit department team status 1 user1 g1 u1 d1 t1 active 2 user2 g1 u1 d1 t2 active 3 user3 g1 u1 d1 t3 inactive 4 user4 g3 u6 d12 t30 active 5 ...
pileup's user avatar
  • 421
1 vote
0 answers
37 views

Update table with data from another table under certain criteria

I need to update a lot of data from one table based on criteria from another table. My tables and records in those tables look like this: This is Users table where i can have many records for single ...
Sahbaz's user avatar
  • 341
-2 votes
1 answer
55 views

Optimizing a TRANSACT SQL statement [closed]

I'm in need to optimize the following TRANSACT SQL statement : ...
Simone Spagna's user avatar
3 votes
0 answers
47 views

SQL query to pivot table into dynamically growing set of columns

I am working on SQL Server I have sample data like this in a table. CustId Bank city rating date rnk 1 Deutsche Delhi 5 10/10/2022 1 1 BOA Pune 6 10/10/2022 2 1 UBS Mumbai 7 10/10/2022 3 1 SBI ...
user3580341's user avatar
1 vote
1 answer
2k views

15 Days of Learning SQL (HackerRank Challenge) - is having multiple queries a good idea in this case?

The challenge is as follows: "Julia conducted a 15 days of learning SQL contest. The start date of the contest was March 01, 2016 and the end date was March 15, 2016. Write a query to print total ...
Yulia V's user avatar
  • 635
1 vote
0 answers
36 views

Can this SQL Query for Grouping Multiple Columns and Date be Improved in any way?

I'm trying to refresh my very rusty SQL skills. I have a table with device logs, collected every 5 minutes. I'm interested in counting the number of times a device is either 'connected' or '...
picklepick's user avatar
2 votes
1 answer
133 views

Extracting authors and books from XML and inserting them into PostgreSQL

There is a tree of start folder, it's subfolders, their subfolders, etc. In each folder, subfolder, etc. there are the same structured XML files stored. books.xml ...
erohtpur's user avatar
1 vote
0 answers
55 views

PHP PDO prepared statement with IN [closed]

Here's my code: ...
neubert's user avatar
  • 111
0 votes
1 answer
58 views

Nested table in query

I have transaction tables called MaterialRequest and MaterialRequestDetails. What I want to check my query and review that it's ...
Basit Sarguroh's user avatar
5 votes
1 answer
61 views

Sum values in different categories by each financial asset

My SQLite database: CREATE TABLE Movimentacao ( mydate DATE , dividend_type VARCHAR(200) , dividends DECIMAL(19, 2) , ticker VARCHAR(300) ); Inserting some data: <...
Felipe Dourado's user avatar
4 votes
3 answers
386 views

Queries to get products selected in multiple stores

Project description I'm making a website listing products. The listing goes as following (See here): Product name Shop name Price in that shop If the product appears multiple times in the table for ...
Alpha.Ars's user avatar
0 votes
1 answer
63 views

Query for sequential column permutations in SQLite

For dummy's sake, let's say that I have a database with columns text, ind and sentid. You ...
Bram Vanroy's user avatar
2 votes
1 answer
416 views

Login authentication using MVP pattern

How can I improve my login script and is there a cleaner way to get the same result? I had this project and redesigned it using MVP patten . Working with this patten is a new challenge for me. It's ...
Ammar Talal's user avatar
3 votes
1 answer
410 views

Why are my read speeds so bad using sqlite?

I know very little about databases and even less about how to optimize them, but I have a problem which calls for a database so here I am... I created a sqlite3 database using the following script: <...
erip's user avatar
  • 916
0 votes
1 answer
51 views

Find dogs who stopped being good boys without ever being good boys - Was HAVING the wrong approach?

The problem I have solved is as follows: Consider a table of dogs, DOGGIES, that records on each row the ID of a doggy, one ...
J. Mini's user avatar
  • 127
-1 votes
2 answers
199 views

Product list from database to web tables/boxes

I am a self-taught front-end developer, trying to land a job, the PHP and MySQL are quite new to me, since I only watched and did some code through Traversy Media courses. This is a test project, ...
Bork's user avatar
  • 11

1
2 3 4 5
30