Questions tagged [sql]

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.

0
votes
0answers
11 views

sql query to make a sum of sale with condition on payment method

I want to get sum of day sale report with condition Payment method like cash and card should be club as one line and other payment as new line CREATE TABLE IF NOT EXISTS `sale` ( `ID` int(6) ...
-1
votes
1answer
10 views

WHERE statement in block where using UNION ALL between them? GROUP BY error

Have some trouble with this error in my code. Expected tokens [EOF]. Found token [GROUP] (Line: 61, Column: 1) All I'm doing is a query on union all between statements. My code looks something like ...
0
votes
0answers
8 views

Sessions are going Inactive status

I am running one sql query to fetch records from a table with multiple threads. Initially all the threads go in INACTIVE status and slowly it starts coming to ACTIVE status. I have created HASH ...
0
votes
0answers
16 views

MySQL: Get date from one column and set in another

I have a table naed mkpfs_store and have 2 columns: creon(timestamp) and original_creon(date). I want to save the values from creon to original_creon. Following is my query: UPDATE mkpfs_store SET `...
0
votes
2answers
21 views

PostgreSQL make data fall into intervals with a step of 5

I have a data from 1 to N, and what I need to do is to make it fall into intervals with a step of five. For example every item from 1 to 5 goes to interval 1, from 6 to 10 into interval 2 and so on ...
0
votes
0answers
5 views

How to Stitch Date and Time into Time Stamps?

In the DolphinDB table, how do I match the date with the time? When my date is greater than 10, there will be an error. What should I do? fv = table(2012.12.01 2012.12.12 2012.12.13 as date, 12:12:...
0
votes
1answer
21 views

SQL Convert varchar to int

I was trying to display the number of days between two dates(column) in my database. The output display was in the varchar data type. How should I convert it into int data type? Following is the error ...
1
vote
1answer
23 views

Cannot resolve the collation conflict error with Temp Table

I am trying to list a number of missing records in the DB, as described in my unanswered question here I am now attempting to fill a temp table with data that should be checked, and comparing that ...
-1
votes
0answers
25 views

Order by is not working with multiple columns and joins in mysql

I need to sort data of multiple columns for my node.js api all the columns return data in no particular sequence. I am using following query.I need all the columns in sequence either alphabetical or ...
-2
votes
1answer
19 views

Looping over table values SQL with condition

I have this table. How to loop over each row, apply for it the code below and set IsAzure column to 1 or 0 (according to result from the code). Something like this from C#, but using sql foreach(var ...
0
votes
1answer
19 views

How to adjust Auto Increment?

Good day to all. So I have lots of data in excel that i needed to insert in the db but I didn't notice I inserted a duplicate value (cause hr didn't sort it out). So anyways, here is the deal [id][...
-1
votes
0answers
12 views

Create trigger after insert to substract value by 1 from another table

I have 2 tables: Flight -id primary -plane_id foreign -economy_seats_left NULL -business_seats_left NULL and Plane -id -total_economy_seats -total_business_seats and Ticket -id -bla -bla -bla.. -...
1
vote
0answers
8 views

Selecting a start line with where geom returns different geom

I have a table with multilinestrings and I would like to find a line which starts at a certain point. I am using: gis=> select * from (select gid, ST_StartPoint(ST_LineMerge((geom))) as start ...
-5
votes
0answers
37 views

Sum more then 50 columns [on hold]

I have This Data DocDate Sector Zone InvQty ReturnQty FreeQty ReturnQtyAmt DscrdQty DscrdQtyAmt 27-06-2019 LHR A 30 14 0 182 14 182 27-06-2019 ...
0
votes
0answers
35 views

SQL variable not updating in the select query in go client

I am running the following queries in SQL. SET @thisid=0; SET @serial=0; SELECT @serial := IF((@thisid != `places`.`id`), @serial + 1, @serial) as `serial`, @thisid := `places`.`id`, `places`.`id` ...
0
votes
2answers
30 views

need to bind values in place of ids(comma seperated)

i want to replace ids with coresponding values example:if column consist of ids 1,2 I need to replace 1 with "Product Videos",2 with "Installation" . I can use case but not able to find a way to use ...
0
votes
0answers
27 views

SQL Server - Find similarities in column and write them into new column

I have a big table with data like this: ID Title -- ------------------------ 1 01_SOMESTRING_038 2 01_SOMESTRING K5038 3 01_SOMESTRING-648 4 K-OTHERSTRING_T_73474 5 K-OTHERSTRING_T_ffk 6 ...
1
vote
2answers
18 views

SQL Server Stored Procedure for updating rows from Table 1 based on rows from Table 2

I have two tables: Table 1 Code Value AAA 100 BBB 200 CCC 300 DDD 400 Table 2 Code NewCode AAA ALPHA BBB BETA DDD DELTA How do you create a stored procedure that will update all the Code ...
0
votes
2answers
30 views

Oracle - NVL(col1,col2) Order By slowness

There is a column in Select clause NVL(b.name, a.name) and I am using this column in Order By due to which the Oracle query has become slow. I tried creating index on the NAME column but of no use. ...
0
votes
1answer
16 views

regexp_substr not working when value changing

I want the min and max marks for each student. Below are the sample marks, I want the uc_min as whatever coming before / and uc_max as whatever coming as after / Below is my code, It is not working ...
0
votes
0answers
9 views

AutoFilter JComboBox Data from Database on typing on the JComboBox

I am trying to filter only valid values contained in the typed text of a JComboBox which is read from the database. E.g From DB, i have 'Makindu', 'Mombasa'. If i type 'a' both the 2 values should ...
0
votes
0answers
18 views

UPDATE FROM with JOIN over ctid leads to Seq Scan

To clarify my problem I have created a test table with the following structure. CREATE TABLE public.test_large ( id int4 NOT NULL, -- Primary Key grp int4 NULL, -- Group ID descr text ...
-2
votes
1answer
31 views

How can I fix this error ? java.sql.SQLException: Closed Resultset: next [duplicate]

I wrote a Java app that generates a report. While generating the report it stops and the stack trace gives me this error: java.sql.SQLException: Closed Resultset: next at oracle.jdbc.driver....
1
vote
0answers
18 views

Nested Join with aggregation in posgres

In my DB, there are two tables EventType ID (Primary key) Name ActivityType ID (Primary key) Name EventTypeID (foreign key) ParentActivityTypeID (Relation with self ID) I have tried with the ...
0
votes
3answers
31 views

Percentage of existence in a group in SQL

Hi I have a requirement of finding the occurrence percentage of specific items in a group. My table is like this Team Objective Status -------------------------------- Team1 Obj1 ...
0
votes
0answers
33 views

Insert into become very slow after adding a left join. What could be the problem?

I left join 5 tables and insert the select result into my target table, 200,000 records costed 30s before I add a new left join in the statement. However,after the addtion of the new left join,the sql ...
0
votes
2answers
34 views

How can I replace a `'` in a string in SQL?

I have to replace special characters in SQL. My problem is with ', because it is used for start and end of string in SQL. I tried: ID = REPLACE(ID, ''', '') ID = REPLACE(ID, "'", "") But both not ...
0
votes
2answers
28 views

SQL to select records where two values in one table are both present as substrings in a text field in a second table

TableOne: LNAME FNAME FILETYPE Smith John A Jones Mary B Brown James B TableTwo: NAME FILETYPE ...
-2
votes
4answers
39 views

Need to find the minimum and maximum value using a JOIN statement

I have got a table here which shows the amount of sales done for a particular date for 3 companies. I need to find the minimum and the maximum sales done for a company and on which date the sales was ...
0
votes
1answer
21 views

I am new in codeigniter and I want to add pagination in my data table with ajax

Currently I am using dynamic data table bootstrap 4 and I want to add pagination in my table View: <form role="form"> <div class="card-body"> <div class="row"> ...
0
votes
1answer
20 views

How to speed up quering same table many times with different conditions?

EF6, asp mvc core and SQL server are used on the background. I have to do many queries to the same table with different conditions, f.e. SELECT COUNT(*) FROM Table1 WHERE a = true SELECT COUNT(*) ...
1
vote
2answers
18 views

node.js - how to insert values from a json array into a sql database

I have incoming json structure like { "type":1, "location":[ {"lattitude":"0", "longitude":"0"}, {"lattitude":"0", "longitude":"0"}, {"lattitude":"0", "longitude":"0"}]...
0
votes
0answers
14 views

Saving or retrieving contents of currently focused file via custom task in VS Code

I'm struggling to find a simple way to save or retrieve the contents of the currently focused file (without saving) via custom task in VS Code. I've been building a custom task to "run" a report from ...
-2
votes
1answer
28 views

sql programming all type

Write a query to display list of students name who all are from IT department. Sort the result based on students name in descending.
1
vote
2answers
20 views

SQL Checkbox search which displays list of items that are in my database

I'm setting up a directory page that displays different workouts depending on what is searched through a text field(which works) and/or checkboxes(Doesn't work) I don't know if it's possible without ...
0
votes
0answers
20 views

Pandas read_sql_query returning empty dataframe index = []?

I am working on a problem where there is a demand table in Postgres that updates once every week. I am attempting to build a script that automates that data pull and shows the differences in weekly ...
0
votes
0answers
13 views

How to SQL rollback previous version of Dacpac using devops/VSTS

I need to rollback the previous version of dacpac using DveOps/VSTS. If any limitation and it is possible? Please give me any ideas. Thanks.
0
votes
2answers
27 views

Finding Distinct Values across 2 tables is not working

I have 2 tables (I've only shown select fields): Table A: <LOCATION CODE> ACT NSWNS OSUSA Parra Parra Parra ACT ACT Table B (A lookup table): <...
0
votes
2answers
17 views

SQL Query to filter where value equals @param unless @param is other

I have a filter dropdown list with the following options in it: 1, 2, 3, 4, 5, Other When the user selects an option I will run a simple SQL query to filter the data by that value such as: SELECT ...
0
votes
0answers
13 views

Create SQL Windows USer account and Grant db_datareader access on all SQL servers using Powershell

Need to create a SQL AD account and grant read access to the master database on all SQL servers using PowerShell script. Below script helps in creating AD account on a single instance. $sqlServer = ...
0
votes
1answer
30 views

Achieve same results without common table expression

My SQL code produce per_month, per_month min, per_month max and per_month standard deviation. But i have done it with CTE. now i want to do without CTE. ;WITH QTY_T AS( SELECT YEAR(...
0
votes
1answer
22 views

How to transform columns and rows?

I can't transform one column to multiple columns and multiple columns to rows. The best way to explain myself would be with the table. Table
1
vote
1answer
16 views

How to use sum over partition (withhout window function) in mysql 5.7

I want to know how mysql 5.7 engine works the same as sum over part. Cannot replace query engine because it is not a personal operation. There was an attempt to resolve it through the @set variable ...
0
votes
1answer
13 views

Need help to list down duplicate function in a responsibility name

I will need to list down duplicate functions within the responsibility name in Oracle I have tried the below sql query select ffl.user_function_name, ff.function_name, rtl.responsibility_name from ...
0
votes
1answer
13 views

How to use an UPDATE within the IF ELSE SQL Server

I'm trying to check if a column exists within a given table. When checking if it exists, I want to update the column with the value 1, if not, create and update. However, every time I run the error, ...
0
votes
1answer
12 views

SQL: How to perform PERCENTILE_CONT of group sum among groups?

Very simply, let's say I have want to SUM the total of a feature within a group. So I partition over a window function: SELECT sum(NumberOfPlayers) over (partition by sport) as SumOfSport Great, ...
-1
votes
0answers
11 views

Table relationship configuration for multiple relationship levels

I'm developing a database for a medium size software where we are going to have a lot of records created daily, right now I do not have an approximated number but I would guess something around 7k to ...
1
vote
1answer
27 views

Cannot get the value in localStorage to update values in my database

I have table which td is contenteditable. To update the value of td in my database I decide to use localStorage. Once the button save is click the inputted value in td will save to localStorage and ...
0
votes
1answer
16 views

How sqlplus “show parameter” result column without wrapped while glogin.sql empty

The question is how show tidy result in one server when glogin.sql is empty? Did not want to use this code in glogin.sql for every db server: -- Defaults for SHOW PARAMETERS COLUMN ...
0
votes
1answer
28 views

How to query MYSQL table to get counts of column occurrence overall and within past year?

I am using MySQL and want to create a query that will count how many times appointments happened per contact_id within the last year, last year, and how many times the occurrence happened overall. ...