I have a temp table (#general) that contains Account number, transaction type, Amount info as below AccountNumber Tran_Type Credit 96551AQ6 TSCNYAEUQF 0.0000000 96551AQ6 TSCNYAEUQF …
Tag: sum
CASE condition and SUM() common table expressions or Group By
Hope some can help ? I have a 3rd party software were i can do custom sql querys but not able to change any of the database. Struggling to get the result i would like. Do I use GROUP BY or CTE to get the result i need? This give me the result below . I have removed Where c=1
Conditional Grouping in SQL
This should be easy, but I’m having trouble with it. I have a results table that looks like this: Notice that the pct column sums to 1.0 for each store. Here’s the code to create this table: I’m trying to group the results by store, then by cust_id while creating a new category A&B if the same cust_id has both
mySQL question on how to add more info to a column
Got this table containing info about customers, dates and their purchases values. Let’s say some of them bought something in November but nothing in December. Now, I am trying to have all the customers + all they spent and to use IFNULL() to the ones that have not bought anything in Dec. I am filtering it for Dec and all
Add additional column to the query output
I have the following query that is grabbing data from a table and combining all the products into one column and counting the quantity of that order. I need to add an additional column to the output though, how can I also add ship_date? This is how the original table is laid out: And this is how the query outputs
My SUM query returns 2 rows, need some advise
I am getting 2 rows(9500) for 111 in the result, could you please advise on the right approach, I need like, Balance = (sum of bought – sum of sold) Query Answer You can use conditional aggregation: If you want this for only one account, you can add a where clause:
Subtract a number from the rows until the number ends to zero
How can subtract a number from the rows to the end of the subtraction in MySQL with query update If have table like this and i want subtract “80” form qoh to get the output I tried by and not work What is the appropriate adjustment to do? Answer If you are running MySQL 8.0, you can do the computation
SQL get Values where some is greater than value with Having not working
I have this code: But it gives me an error. I can not figure it out. Happy for every help! Answer Having clause execute after group by and then select so you have to use aggregated function with having as following
Count json tags in sql
I have this json strings And know i want the following output I wanted to do this with a sql query. If you know how to do this, thanks in advance! Answer If you’re not using MySQL 8, this is a bit more complicated. First you have to find a path to a name element that has the value phone
MySQL Debit/Credit cumulative balance
I would like a cumulative DR or CR balance for the following table: For the above table, a cumulative Balance column would be: Decreasing a DR below 0 makes it a CR Decreasing a CR below 0 makes it a DR Where balance is 0, value is 0 DR It could be calculated as CR’s being a negative value, but