Category "sql"

How to I order by a sql table multiple times?

I don't think I worded it correctly but how do I use order by to sort a table multiple times by a different dimension. For example if I wanted to sort by type o

Two-part conditional sql statement

The statement below is querying a log table and I'm trying to get the max budget depending on the scenario if falls within. Error message: Expressions referenc

Two conditions in where tag of Liquibase

I want to add two conditions in where tag of liquibase and exception is thrown: Reason: liquibase.exception.DatabaseException: Unknown column 'uid' in 'where cl

return the row where before and after value is lower

I have a table that looks like this: name val 1 1 2 2 3 1 4 2 5 2 6 10 For each row,

How to update the timeout field in the attendance table for a given user_id, logdate and status using if else statement?

I have been trying to update the timeout for a given user_id, logdate, and status but my update statement is not working or may be my other if else are not corr

Error with creating a laravel foreign key

I'm trying to create a relational database and this is the error i get SQLSTATE[HY000]: General error: 1005 Can't create table somedumbtable.meals (errno: 150

Select item that is different in each of group by a column

I have this sample table +--------+-------------+ | DBName | Description | +--------+-------------+ | A | Car | | A | Boat | | B

django annotate whether exists or not

I have a query I'm using: people = Person.objects.all().annotate(num_pets=Count('pets')) for p in people: print(p.name, p.num_pets == 0) (Pet is ManyToO

get the most common value for each column

I'm attempting to create an SQL query that retrieves the total_cost for every row in a table. Alongside that, I also need to collect the most dominant value for

Check if a number is prime or not in mysql

I am wondering what's the best way to check whether a number is prime or not using sql. I was able to generate the sequence of numbers from 1 to 1000 but I woul

Is there a way to search one table for certain values, and if successfully found, then update a different table?

Good afternoon all, This is my first time using SQL, so forgive me for being new. I have three different tables that I've created: CREATE TABLE employee (ID int

How do I produce a new column with values based on a Partition of one column while also based on the values of two additional columns (BigQuery)?

I have a table that records all the different statuses for a list of Jobs with timestamps. So the ID column has many Ids that appear several times as their stat

GBQ Transpose Dynamically without Execute Immediate

Hi All trying to figure out a way to transpose data in columns dynamically. In the data the distinct number of Traits will increase/decrease. I know I can hardc

Smarter SQL UPDATE between two tables (bill and bill rows)

I have these two SQL tables: Bills (BillId, Folio, Date, ProductId) BillsRows (BillRowId, BillId, ProductId, Lot, Quantity, Price) ProductId is optional in Bil

Target row updated by multiple source rows

UPDATE tb FROM Table1 tb, ( SELECT oreplace(data, '.', '') AS data FROM Table2 ) tb2 SET column = 'Y' WHERE tb.column1

Cannot connect to SQL Server except with domain admin account

I am running into an issue where my .net application (C#) will not connect to SQL Server when ran by a domain user. Exception is: The underlying provider faile

On delete cascade on foreign key not working [duplicate]

I am doing a TODO list app and I'm trying to delete a list and every task which has the referencing listID.The problem is that on delete casca

Hive SQL regexp_extract (number)_(number)

I'm new to hiveSQL and I'm trying to extract a value from the column col_a from the data df which is in this format: \\\"id\\\":\\\"101_12345\\\" I only need to

How to order by many to many relationship in Sequelize?

I have a many to many relationship between User and Category through UserCategory as below. let user = await User.findAll({ where: { id: req.query.user

width_bucket not returning buckets of equal width

I'm using Postgres version 9.6.9 and attempting to use width_bucket() to generate a histogram with buckets consisting of equal widths. However, the query I'm us