Latest Questions

Get Answers to Your Coding Questions

0
Votes
Published 14 Nov, 2022
How to Query by line in SQL

I have the query and table below, how do I select the 1st line of each category of column TeamboardId? SELECT * FROM Job WHERE HandLingTimeSeconds = '60' JobId TeamboardId 1 1 2 1 3 1 4...

2
Votes
Published 15 Nov, 2022
How to get the intersection length of touching geometries with ST_Touches

I am trying to develop a query in Postgis, where it can solve this problem: I have a geometry and I wanna know which of the polygons that touches it, there is the highest contact area of this geometr...

2
Votes
Published 30 Nov, 2022
How to account for Postgresql rank() ties

I've a table teams with 30 rows and has a handful of statistics stored as attributes. For example, goals for, goals against, etc and I've created a view that uses rank() and does a good job ranking th...

1
Votes
Published 19 Nov, 2022
How to find maximum, latest and average profit in sql

I have a table where i have user_id, item_id , profit_date and profit as a column. what i want is avg profit, maximum profit and latest profit for each user and item. i am able to find max and avg but...

358
Votes
Published 07 Nov, 2022
How to skip certain database tables with mysqldump?

Is there a way to restrict certain tables from the mysqldump command? For example, I'd use the following syntax to dump only table1 and table2: mysqldump -u username -p database table1 table2 > dat...

0
Votes
Published 27 Nov, 2022
How to update a text field with broken JSON literals in PostgreSQL?

I have a lot of character varying records in this format: {'address': 'New Mexico'}. I would like to update all those columns to have it like this: New Mexico. I've been investigating how to do it, an...

0
Votes
Published 02 Dec, 2022
How to correct bad sql grammar when passing data?

This is my JDBC file with a the following sql query: private static final String UPDATE_QUESTION = "UPDATE Quiz SET type=?, questionIndex=?, choiceNum=?, question=?, choiceA=?, choiceB=?, choiceC...

0
Votes
Published 06 Dec, 2022
How to select most recent record for each ID

I am going to financial data of peers of a company. I have 10 peers for a particular company and the financial data is captured at regular intervals (monthly, quarterly, etc). However since the data c...

23
Votes
Published 05 Dec, 2022
How to generate unique id in MySQL?

I'm programming a script using PHP and MySQL and I want to get a unique id (consisting of a string: capitals and small letters with numbers) like: gHYtUUi5b. I found many functions in PHP that can g...

1
Votes
Published 05 Dec, 2022
How to split comma separated value into their respective columns in SQL Server?

I have a table with comma-separated values in it. I need to split that values into their respective columns. The values can be any number starting from 1 to 10. For example, the value '1,3,4' should s...

0
Votes
Published 18 Nov, 2022
How to query a tree like structure with multiple tables recursively?

Here is my ER diagram. If I know the user_id, how can I get a single user's user data=>projects=>boards=>posts using a single SQL query? I have found out about recursive CTE, but all of the...

2
Votes
Published 12 Nov, 2022
How to find out SQL Server default instance name?

I have three SQL server instances on my computer. How can I find out which is the default one? var conn = new SqlConnection("Data Source=.;Initial Catalog=SampleDb;Integrated Security=True")...

1
Votes
Published 15 Nov, 2022
How to first join tables and then filter rows to keep the greatest per group

I'm trying to write a SELECT statement that first joins two tables and then filters rows, by keeping the max value per group. Example The following two tables describe visitors in a zoo. visitors tab...

1
Votes
Published 23 Nov, 2022
How to do conditional aggregate based on values of another column?

I have a table called device_data that looks like below Column | Type | Collation | Nullable | Default ----------------+-------...

0
Votes
Published 02 Dec, 2022
How to get the most repeated value of x column grouped by z column - ORACLE SQL

I have a select that returns a table such as: weekOfTheYear mostRepeatedID 01 a 01 b 01 a 02 b 02 b 02 a and what I need is: weekOfTheYear mostRepeatedID 01 a 02 b...

3
Votes
Published 11 Nov, 2022
How to use first_value window function to get last non null value in Postgresql

I want to perform a fill-down activity in PgSQL DDL: create table brands ( id int, category varchar(20), brand_name varchar(20) ); insert into brands values (1,'chocolates','5-star') ,(2,null,'dairy...

1
Votes
Published 15 Nov, 2022
How to return rows containing decimals in a range

I have the following table: Rows Decimals First 1.1.1.3.2 Second 16.1.1.1.89.1 Third 3.1.1.1.177.2 Fourth 1.1.1.1.178.3 I only want to return the rows where the second to last decima...

4
Votes
Published 03 Dec, 2022
How to concatenate arrays in Snowflake with distinct values?

I have a MERGE scenario with an ARRAY_AGG() function in the main script. Once I have a match I'd like to combine the arrays from the source and target table but don't want to add existing values. I've...

19
Votes
Published 11 Nov, 2022
How to count number of records per day?

I have a table in a with the following structure: CustID --- DateAdded --- 396 2012-02-09 396 2012-02-09 396 2012-02-08 396 2012-02-07 396 2012-02-07 396...

1
Votes
Published 18 Nov, 2022
How to select different columns based on the value of specific column?

There are two tables with similar contents.I need to join them on the key 'id' to compare the value.They look like below: table_A id item_name item_value 1 cost 1.00 1 price 3...

0
Votes
Published 28 Nov, 2022
How to Insert values into datatable from another datatable SQL

I have table1 with the following data : ID Name Date 1 Paul 01-11-2020 1 Paul 03-11-2020 and have table2 only with a Date column: Date 02-11-2020 I want to get output from th...

105
Votes
Published 23 Nov, 2022
How to check for null/empty/whitespace values with a single test?

I'd like to write a SELECT statement that uses just one test to return columns with no value (null, empty, or all spaces). I thought this would work: SELECT column_name from table_name WHERE column_...

17
Votes
Published 14 Nov, 2022
SQL How to replace values of select return?

In my database (MySQL) table, has a column with 1 and 0 for represent true and false respectively. But in SELECT, I need it replace for true or false for printing in a GridView. How to I make my SEL...

1
Votes
Published 01 Dec, 2022
How to add a datefield attribute with integer attribute using ActiveRecord

I have a rails model with two attributes, one is a datetime field and the other is an integer. I'm trying to add a scope using both these fields & it gives me incorrect results. ModelName.where(&q...

7
Votes
Published 28 Nov, 2022
How to exclude a column from SELECT query?

I have 100 columns in a table and I want to list 99 columns except a particular one. How to exclude that columns name?

0
Votes
Published 27 Nov, 2022
How to query on-premises SQL Server database using power automate varible?

I am trying to query an on-premises SQL Server database using a power automate variable. Is there any suggestions or is this even possible for the time being? I have attempted the following: Using “E...

0
Votes
Published 18 Nov, 2022
How to get year and quarter for sysdate in Oracle Sql

I want to get the quarter and year depending on the sysdat in Oracle sql. For example i want expected result value as 2022q3 for current quarter. I can get the quarter using below query: select to_ch...

396
Votes
Published 19 Nov, 2022
How to see the raw SQL queries Django is running?

Is there a way to show the SQL that Django is running while performing a query?

3
Votes
Published 16 Nov, 2022
SQL: how to average across groups, while taking a time constraint into account

I have a table named orders in a Postgres database that looks like this: customer_id order_id order_date price product 1 2 2021-03-05 15 books 1...

0
Votes
Published 09 Nov, 2022
How to prevent entering the same value second time in sql?

I have the following problem: I have to create table with projects and employees. Employee can be assigned to few projects, but he cannot be assigned twice to the same projects. How can I prevent doin...