Postgresql group by day, week and month examples

at the end of any product there will be a reporting interfaces for counts. let say you build a advertisement site which gives people to publish their products on the site. they will want to see how many people visited their product in daily basis or weekly. I used to do this in mysql like this SELECT create_time as Date, count(id) as 'Count', FROM views_of_product group by date_format(create_time, '%d %m %Y') order by date_format(create_time, '%Y-%m-%d') desc limit 7 this will nicely show last seven days views. but I needed to do same thing in postgresql. and like other days its not easily to find. I should check other report codes from project but no I allways research on google :) anyway here is my code: ...

September 30, 2023 · 2 min · Özkan Pakdil

Turning an array clockwise or counterclockwise

Turn an array clockwise therefore the last element comes to first and all hops to right. And counterclockwise meaning last element comes to first and others hops to their left. import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Solution { public static void main(String[] args) throws IOException { int[] arr = new int[]{1, 3, 5, 7, 9}; int K = 3; turnTheArrayToRight(arr, K); System.out.println("-----------"); turnTheArrayToLeft(arr, K); System.out.println("-----------"); // no need to reinvent the wheel. List l = new ArrayList<>(); Arrays.stream(arr).forEach(i->l.add(i)); Collections.rotate(l, K); // rotate right System.out.println(Arrays.toString(l.toArray())); Collections.rotate(l, -1 * K); // rotate left System.out.println(Arrays.toString(l.toArray())); } private static int[] turnTheArrayToRight(int[] nums, int k) { for (int j = 0; j < k; j++) { for (int i = nums.length - 1; 0 < i; i--) { int temp = nums[i - 1]; nums[i - 1] = nums[i]; nums[i] = temp; } System.out.println(Arrays.toString(nums)); } return nums; } private static int[] turnTheArrayToLeft(int[] nums, int k) { for (int j = 0; j < k; j++) { for (int i = 0; i < nums.length - 1; i++) { int temp = nums[i]; nums[i] = nums[i + 1]; nums[i + 1] = temp; } System.out.println(Arrays.toString(nums)); } return nums; } } Output ...

September 28, 2023 · 2 min · Özkan Pakdil

Table Rollback Problem

Create a class that populates a table represented in the following way. You can think of this as a nested hash/map/dictionary structure. { "row1": { "col1":"foo", "col2":"bar" }, "row2": { "col1":"baz" } } The class should support the following methods: createRow(rowName): Creates a new empty row of the givenname. Do nothing if a row with that name already exists deleteRow(rowName): Deletes a row with the given name. Donothing if a row with that name doesn’t exist updateCell(rowName, columnName, newVal): Sets the value ofthe cell at the given row/column coordinate to the new value. If the row doesnot exist, do nothing. These actions are grouped together in transactions. Theactions above can only be performed as part of a transaction. The class should also support the following methods: ...

September 20, 2023 · 3 min · Özkan Pakdil

Solving the Remote Keyboard Traversal Problem: Navigating the Grid Efficiently

The Problem Write a program to search a movie title using screen keyboard with minimal traversal (e.g. Searching for a title Using ROKU/Apple TV remote on Netflix). Input keyboard can have all the characters in any order. Given : Movie title and initial position of remote selection We have five buttons in remote: UP, DOWN, LEFT, RIGHT, OK Keyboard: Input remote could be like this (as it buttons could be in any order) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z For Example: Initial position of remote: A Movie title: BHE Result: RIGHT, OK, RIGHT, DOWN, OK, RIGHT, RIGTH, UP, OK (Right answer) Result: RIGHT, RIGHT, LEFT, OK, RIGHT, DOWN, OK, RIGHT, RIGTH, UP, OK (incorrect, not the shortest one) this problem can be categorized as a grid navigation or grid traversal problem ...

September 1, 2023 · 3 min · Özkan Pakdil

Add `open with intellij` into context menu in linux mint

Add code below to ~/.local/share/nemo/actions/intellij.nemo_action [Nemo Action] Name=Open in Intellij Comment=Open in Intellij Exec=intellij-idea-community "%F" Icon-Name=intellij Selection=Any Extensions=dir; Then in files go to folder you want to open with intellij then right click and choose open in intellij.

June 11, 2023 · 1 min · Özkan Pakdil