Consider the following schema: Student(snum, sname, major,level) Class(cname, meets-at,room, fid) Faculty(fid, fname, depname) Enrolled(snum, cname) write an SQL query to find the names of all the classes that don’t meet in room R128 with the smallest number of students(compared to all other classes). A…
Tag: sql
Getting all rows with common value in column A and specific value in column B
In MySQL I have table matcher_table with columns matcher and type. Records which are put here can have many different values for type column. One type matches another one only when value for matcher …
Mysql 8 How to use an if inside a stored procedure and using cte
I am using a CTE inside a stored procedure, and it works ok, but the problem is when I try to add a conditional, I got the following message: You have an error in your sql .. Syntax to use near ‘IF. Answer You cannot use an IF statement in a query. It is meant to execute a block of
How to Fix Error Msg 41337, Level 16, State 100 in Create Memory Optimize table in SQL Server
I want to use a memory optimize table and I got below error – how can I fix it? Any idea will be helpful. Msg 41337, Level 16, State 100, Line 1 Cannot create memory optimized tables. To create memory optimized tables, the database must have a MEMORY_OPTIMIZED_FILEGROUP that is online and has at least o…
SQL compare the incremental difference from a column
Let’s say I have a table with the columns CurrentDateTime and CurrentValue where the CurrentValue column mostly increments. Sometimes though, the CurrentValue resets, this is where the issues start. …
Is there an optional prepared statement in SQL for different specific levels of querying
Suppose I have a query that returns the total monthly sales of individual products in my database: Is there a way to query various levels of specificity without creating many similar queries. For instance, If i enter Espresso for the product, leave out the milkoptions entry, and enter small for size, could I …
Find data from json/jsonb column by array in Postgresql
I have a column with json/jsonb data. Database is postgresql. column data sample {“postId”: “p522”, “groupId”: “g11”, …} {“postId”: “p5ds”, “groupId”: “g234”, …} {“postId”: “p5cz”…
Flagging amount thresholds reached per user
Story: Two conditions: I need to calculate the amount of days it takes a user to spend over 20, 50 and 100$ based on his register_date If someone’s first purchase is > 100$ then the amount of days …
How can i get a zero in front of the week number when it is a one-digit number?
I want to get the week number, and I did using DATEPAR(WEEK,DATE) , however, one-digit week numbers do not come with a zero in front. Basically I need to get 01, 02, 03 instead of 1, 2, 3.
How to dynamically select columns in Oracle? is this possible?
I have the below data set: NAME 2012 2013 2014 2015 2016 2017 2018 2019 JOHN 180 185 192 205 199 198 …