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.
1,463
questions
1
vote
3
answers
1k
views
Saving Multiple Lists to Database - C# Forms
I am trying to store multiple lists to a database but I'm struggling on finding a better way of doing it, as the way I am doing it now, seems to be incorrect.
On my form, I have 6 different legs. Each ...
0
votes
2
answers
185
views
Version 2: Display visitor's number on your web page (changed code after getting answer for first version)
Version 2: Display visitor's number on your web page (changed code after getting answer for first version).
The first version is here: Display visitor's number on your web page
The "visitors&...
0
votes
1
answer
281
views
Display visitor's number on your web page
Display visitor's number on your web page.
The "visitors" table has only one column (visitor_count) and only one row. The column's initial value is 0.
I know goto should not be used but then ...
3
votes
2
answers
112
views
Change query strings with a Bash script
The following script changes start and end dates of several queries saved as files in the folder /app/queries. It is used by executing the script and passing two ...
1
vote
1
answer
40
views
PostgreSQL query which return metrics joining different tables
I have a query that can be seen on this fiddle and I'm relatively new to PSQL, having a few months of experience.
DB Fiddle
As mentioned in the comment I should put the query here and the code is ...
2
votes
1
answer
645
views
SQL query to find expenditures of employees who have exceeded their limit
I've 2 tables emp and expenditure.
Emp:
ID, NAME
Expenditure:
ID, EMP_ID, AMOUNT
Each emp has a limit of 100 that he/she can ...
1
vote
1
answer
74
views
Updating multiple database tables when products are shipped back by customer
So, in this example I have to make these changes in my tables:
Select Product Data => SKU, QTY
Insert into shipping_back table
Update in shipping_back to current date
Update in customers to ...
2
votes
0
answers
22
views
Plpgsql function that redacts substrings wrapped with double pipes `||`
I'm using Postgres 14 and I've written a function (for use with Hasura GraphQL Computed Fields) that transforms a TEXT field, replacing all instances of spoiler-annotated text (e.g. ...
3
votes
2
answers
152
views
RawSqlQuery minimizing risk of field name confusion
Is there a way to make the following code more maintainable?
...
-1
votes
1
answer
57
views
Which one is faster and preferable when doing aggregate function to the data in sql? CASE WHEN or WHERE? [closed]
I have following simple sql code to select the number of rows that meet a specific criteria:
SELECT COUNT(CASE WHEN /*condition*/ THEN 1 END) FROM table_name;
...
1
vote
1
answer
78
views
Search controller logic to search through models and manufacturers
I have the following Laravel controller that searches through two models - Manufacturer and SearchTerm (which contains models of manufacturers, synonyms of models as well as common misspellings) using ...
1
vote
1
answer
132
views
Creating SQL query for relative timeframes and multiple tables
What I want to achieve:
I have several tables of the following schema:
+------+-------+
| date | val |
+------+-------+
| DATE | INT64 |
+------+-------+
I want ...
2
votes
2
answers
175
views
Is this a good way to process an order? (SQL+PHP)
I'm making a simple webshop, it's not the full code, there are more security procedures. I'm just want to know your opinions. Thank you.
These SQL tables I have:
(I have more column in this table this ...
2
votes
1
answer
76
views
Calculate time interval excluding breaks
I have a solution for a question I asked on SO:
I am trying to create a database where I also need to find the time
difference inside a record. However, timediff() ...
1
vote
1
answer
132
views
Creating database and two tables linked by foreign key
These commands do what I want, but I'm trying to find out the best approach for this. My main areas of concern are: error handling and disposal of resources. In regards to error handling, I'm catching ...