Skip to content

Get the sum of rows using sql query

Suppose I have this table structure: I want to sum the quantity for the same name and last name and get the result as below Is it possible to get this result in a single SQL query ? it is easy to get the SUM with the GROUP BY but did not find a way to keep the Buy and

SORT dates that are not in same format – SQL

I have below table and I want to sort it by ascending order. Below command would work except not all of my dates are in correct format. Majority of them are in YYYY-MM-DD and few are in DD/MM/YYYY format. How would i sort them? Can i convert all of them in to on standard format and do the sorting? order

Case statement with division

I have case statement below as but am getting error on syntax error, is there proper way to divide in case statement? thanks Answer You need to add quotes to the desired column name (if it’s not going to follow traditional naming rules. Change: To: Btw, the exact syntax error you got was Syntax error: u…

Error converting data type varchar to bigint: INSERT INTO SELECT

I keep getting this error when trying to execute a stored procedure and am not sure why: Msg 8114: Error converting data type varchar to bigint. Please see my SQL query below: I believe the error is emerging because of the UniqueStudentID I have tried using CAST & CONVERT around the SELECT line but still …

Convert Date format in SQLite Database

I have a SQLite Database and I mistakenly loaded a lot of data with mismatching date formats. There are dates formatted as: MM/DD/YYYY and dates formatted as: DD-Month Abbr. – YY. I would really like them all to be YYYYMMDD. Is there a way to reformat all of the dates to match the preferred format? Than…

Percentage calculation in SQL

I have some cars in a table along with the year they came out, and I’m trying to calculate the percentages of the cars that belong in the 4 following age groups: 0-4, 5-9, 10-19, 20+. I tried to do this in 3 different ways: 1. I got this error: I got this error: I got this error: Any ideas