Skip to content

SQL – Delete random rows where sum is equal to given number

I want to get some random rows from the given table where the sum is 250(this can be changed). I don`t need to 100% accurate but can be approximate. Like for 250 (1,5,7) Note:- My table has huge data. Answer For any specific numbers, you can return the closest sum using logic with joins. For instance for 3 nu…

Insert row with uniqueidentifier

This is a snippet from a stored proc that creates a database. We have a table with uniqueidentifier PK. I’m trying to insert a row with an empty guid as the PK: The error messages are Can’t see what’s wrong with the VALUES clause but I guess it has something to do with the final quote, altho…

All categories for each week and group

Hi I have a data source as such Data: Weeknum Group Priority Total 202106 A High 10 202106 B Medium 15 202107 A Medium 88 Priorities: Priority High Medium Low The data has already been grouped such that each weeknum+group+priority is unique. What I need to do is return the full list of priorities for each wee…

Oracle SQL Pivot with Conditions convert rows to columns

I have the a table ITEM_SF with the following data I want to convert the data into Columns with a few conditions: My desired result is to show Charges, Discounts , Amount Paid and Tax Charges include (BookFees, HealthFees,RegistrationFees,SSCFees,TuitionFees,GeneralFees) Charges , Discount is Sum of ITEM_AMT …