Skip to content

Tag: sql

Count amount of same value

I have a simple task which I to be honest have no idea how to accomplish. I have these values from SQL query: I would like to display a bit modified table like this: So, the idea is simple – I need to append a new column and set ‘Multiple’ and ‘Single’ value depending on if custo…

How to get next item in mysql order by createdAt

My frontend app can list of my items order by createdAt (for sure by calling API): Output is for example: Id of each item is UUID (there in example just myId*). I can open detail of item by url /item/detail/myIdPPP and on this detail I have GO TO NEXT item. The problem is, that I don`t know how to create

Default value in select – SQL

I want to select the sum of the biggest and the lowest numbers in specific column of table, I get it well but I also need to set a default value in case if the column is empty, so far I tried this: And if my table is empty I want to get a single value with default value like

Sharding a RDBMS (SQL) database

I am reading about sharding and I understood it upto some context. But most of the material I read says that sharding (horizontally scaling) RDBMS is a challenging task. But I don’t see why NO-SQL is easy to shard and RDBMS would be tough to shard? My understanding is: some NO-SQL provides inbuilt shard…

SQL query pivot, move values to top

I’ve created a PIVOT query and the results are fine, however. I would like to flatten the rows so to speak and move all values to the top of the list and NULLS to the bottom. http://sqlfiddle.com/#!18/7d17d/6 Instead of this: I would like to create something like this: Answer Change your ROW_NUMBER() to…

How to group by month and year?

I have a table PURCHASE with a date column PURCHASEDATE which is in DATE format. I’m trying to get the purchases grouped by month and year. To do so, I try with: I have also tryied with GROUP BY EXTRACT(MONTH FROM PURCHASEDATE), EXTRACT(YEAR FROM PURCHASEDATE) but neither worked. I’m rusty with SQ…