Category "sql"

Selecting values from column defined by aggregate function

I'm currently struggling with a query and need some help with it. I've got two tables: messages { ts_send, message, conversations_id } conversations {

Efficient way to edit the last line of a text file in Python

I have a Python script which creates a large SQL insert file of about 300,000 lines. The problem with this is that the last line of the file ends up looking lik

Test for Upper Case - T-Sql

All, How can I check if a specified varchar character or entire string is upper case in T-Sql? Ideally I'd like to write a function to test if a character is u

Using Associative arrays

I'm trying to access a position of a associative array which is inside of another array. Here is my array: Array ( [order_data] => stdClass Object

Query to order by the last three characters of a column

Query the name of any student in STUDENTS who scored higher than 75 marks. Order your output by the last three characters of each name. If two or more students

Return to default value after field equals zero

So I need help in trying to make a database field where it's default 7 and each day minuses 1 until its 0 then the day count starts again from 7. Is it possible

Retrieve row where sum of column is greater than other column of different table

I have two database tables. First table: | ID | Sub-Name | Marks | 01 | french | 50 | 01 | russian | 50 | 02 | french | 30 | 02 | russian

How can I SELECT the first row with MAX(Column value)?

I want to select only one row from a table. This row holds the maximum number in the table. I have tried to use MAX Fun but it didn't work for me. I use two ta

Sum with nulls "not working" in SQL Server / Azure

I'm trying to average a set of columns and exclude rows with zero from the denominator by using a case statement within an AVG() function. I read that avg() exc

set a column to copy a column from another table (on condition)

What I currently have is: UPDATE card, records IF(records.date_returned == null) THEN SET card.last_seen = records.date_loaned ELSE SET card.last_seen = records

Query to get top 5 users by total month sales amount

I was hoping you could help me figure this out. I would like to run a query that would search a table and all it's rows and the date matches the current month.

Adding LIMIT to ARRAY_TO_JSON or ARRAY_AGG

In a 2-player game using PostgreSQL 9.6.6 as backend I have defined the following custom stored function for retrieving chat messages for a user: CREATE OR REP

Mysql PREPARE statement is taking much times at the time of record insertion

I am using PREPARE statement in store procedure but it is taking much time at the time of records insertion. Please suggest me the replacement for PREPARE state

How to use like in MySQL query in Grafana?

I am working in grafana with MySQL. I have a template variable and it has multiple values and I want to use that template variable with MySQL query using 'like'

How to organize variable IDs that depend on each other in MySQL

I'm creating a database for all the Magic the Gathering cards... The card table looks like this: cardID name text rarityID colorID editionID other colu

How to read a csv using sql

I would like to know how to read a csv file using sql. I would like to use group by and join other csv files together. How would i go about this in python. exa

How to get distinct values from a column with all its corresponding values in another column

I have a table table_categories (id INT(11), cname VARCHAR(25),survey_id INT(11)) I want to retrieve the values for the column cname without duplication, that

INSERT INTO MySQL statement failing [closed]

I am dynamically forming MySQL statements in PHP and can't figure out why this one is failing to execute: INSERT INTO users ( `email`, `pa

How to effectively search through MySQL DB with multiple searcheable columns?

I have a table with 60 boolean (TINYINT(1)) searcheable columns. User has possibility of using any subset of the given columns as search condition. Based on tha

Oracle SQL query to list weeks between two dates

I have one requirement START_DATE : 03/01/2018 END_DATE : 31/01/2018 I need a query which will list all the weeks starting date and end date between these two