Skip to content

Tag: sql

How compare dates that are equal when one has time as well

I’m trying to compare dates and it looks like I’m doing it like examples online, but I only see the rows of dates returned when I do >= for the comparison. When I just use = it doesn’t return anything. This is my query with >= for the date comparison: I see a lot of this sort of thing …

Find names based on max number dynamically in SQL

I have a data set like this: Table A: What’s the maximum number of Place on which a Partner has spent money and who are these Partners? Display only the Partners reaching this max number I tried this: But I feel like its not the right logic. What am I missing? Answer There’s really no need for you…

Quartiles in Postgres

I have payment amounts like so – How do I divide records like this into quartiles. It doesn’t have to be perfect. For example, the data in the question would transform like so – Ids 124049 and 2323 are given the same quartile because those payment values are close together. Answer you can us…

Show when order number is unique for the item number

I attached a simple table with two columns, Item number and Order number. In the example attached only item number C5664 and A9930 met the criteria. How do I write this code in SQL? Answer If you group by the item numbers then the unique count for the order numbers will be 1

Oracle procedure saving SYSDATE

As part of a larger procedure I’m trying to write some code, which saves SYSDATE into a variable but I’m running into a problem. I narrowed it down to the following. Can someone please help me out. Answer In PLSQL you can just assign: if you insist on sql all you have to do is to add into after se…