Skip to content

Instantly share code, notes, and snippets.

@hidayat365
hidayat365 / crosstab.sql
Last active October 8, 2021 07:17
MySQL CrossTab
PS C:\Users\hiday> mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 10.5.7-MariaDB-log mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use test
@hidayat365
hidayat365 / code.html
Created July 8, 2021 10:48
Code in HTML
<div class="tab-content" id="curl" style="display: block;">
<div class="tab-content-button">
<button id="copy-curl" style="font-size: 12px">
<svg aria-hidden="true" class="svg-inline--fa fa-copy fa-w-14" data-fa-i2svg="" data-icon="copy" data-prefix="fas" focusable="false" role="img" viewbox="0 0 448 512" xmlns="http://www.w3.org/2000/svg">
<path d="M320 448v40c0 13.255-10.745 24-24 24H24c-13.255 0-24-10.745-24-24V120c0-13.255 10.745-24 24-24h72v296c0 30.879 25.121 56 56 56h168zm0-344V0H152c-13.255 0-24 10.745-24 24v368c0 13.255 10.745 24 24 24h272c13.255 0 24-10.745 24-24V128H344c-13.2 0-24-10.8-24-24zm120.971-31.029L375.029 7.029A24 24 0 0 0 358.059 0H352v96h96v-6.059a24 24 0 0 0-7.029-16.97z" fill="currentColor"></path>
</svg>
</button>
</div>
<div class="tab-content-code">
<pre class="highlight highlight-curl prettyprint">curl --location --request GET 'https://partner.api.bri.co.id/sandbox/v2/inquiry/888801000003301' \
@hidayat365
hidayat365 / sqlserver-tuning.sql
Last active February 3, 2021 12:06
Queries for SQL Server Performance Tuning
DBCC FREEPROCCACHE;
-- -----------------------
-- Find Long Running Query
-- Execute the query inside target database
-- -----------------------
SELECT st.text
, qp.query_plan
, qs.*
FROM (
@hidayat365
hidayat365 / before-insert.sql
Created July 22, 2013 02:47
Penomoran Faktur Otomatis Menggunakan Trigger Before Insert di MySQL
mysql> use test
Database changed
mysql> ----------------------------------------
mysql> -- create table penjualan
mysql> ----------------------------------------
mysql> create table penjualan (
-> id int auto_increment primary key,
-> no_faktur varchar(50) not null
-> )
-- master table
create table transactions (
id serial primary key,
code varchar(60) not null unique,
date integer not null,
value decimal(15,2) default 0,
remarks text
);
-- details table without generated column
@hidayat365
hidayat365 / gist:4706105
Last active May 8, 2020 08:21
PostgreSQL cross-tab sample
-- -------------------------------
-- MySQL Only
-- -------------------------------
with grade_calculation as (
select '00001' student_code, 'N001' course_code, 90 grade union all
select '00001' student_code, 'N002' course_code, 95 grade union all
select '00001' student_code, 'N003' course_code, 80 grade union all
select '00001' student_code, 'N004' course_code, 75 grade union all
select '00002' student_code, 'N001' course_code, 70 grade union all
select '00002' student_code, 'N002' course_code, 80 grade union all
@hidayat365
hidayat365 / db_size.sql
Last active July 31, 2019 11:24
MySQL Database and Table Size Query
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size (MB)"
FROM information_schema.tables
GROUP BY table_schema;
SELECT table_name
, round(((table_rows) / 1024 / 1024), 2) as "Row Count (mil)"
, round(((data_length) / 1024 / 1024), 2) as "Data Size (MB)"
, round(((index_length) / 1024 / 1024), 2) as "Index Size (MB)"
, round(((data_length + index_length) / 1024 / 1024), 2) as "Table Size (MB)"
@hidayat365
hidayat365 / fk-basic.sql
Last active June 23, 2019 03:57
Dasar penggunaan Foreign Key (FK) di database relasional (RDBMS)
Nurs-MacBook-Pro:~ nurhidayat$ /Applications/XAMPP/bin/mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 307
Server version: 10.1.38-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
@hidayat365
hidayat365 / validate_pairs.php
Last active January 29, 2019 04:18
Tantangan PHP Group: Validasi Input Array Mencari data Pairs
<?php
function my_var_dump($prefix, $data) {
echo $prefix . ": ";
array_walk($data, function($val,$key) {
echo json_encode($val) . ' ';
});
echo "\n";
}
function validate_pairs($data, $sum) {
@hidayat365
hidayat365 / running_total.sql
Last active November 12, 2018 07:51
Windowed Running Total MySQL feat. @RidhoPrasetya
D:\xampp\mysql\bin>mysql.exe -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.