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…
Tag: sql
Update specific column within the same table and add limit – PostgreSQL
I would like to update the value of a column within the same table by transforming its former value, but I would like to first test it with the first 10 data according to its created date. I am getting this error though Here is my sample code: Any syntax that would make this work? Answer Hmmm . . .
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…
Can we access a record in SQL table using primary key in O(1) time?
I want to know that while finding a record using the primary key does RDBMS takes O(1) time or not? Answer No. In all databases that I know of, the primary key index is a B-tree index. Finding a particular element in such an index is an O(log n) operation, not O(1). Note that for the sizes of databases, O(log
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…
How to neglect timestamps when inserting date to MySQL database
I want to insert a date into MySQL table. But, even if I use strftime(), the timestamps are showing like 00:00:00. How can I get rid of it? Output: Answer Obviously the column Date has data type DATETIME or TIMESTAMP. If you don’t need the time part of the column, you should change the data type to DATE…
Update & Select a MySQL table in FIFO queue with non-unique identifiers
I have this table documents based on client’s set of data. Only provided key is documentId, but it’s non-unique (and rowId is mine, not client’s). This table also shows which documents have been processed and which have not, plus some additional data. isProcessed is a generated column (isPro…