Skip to content

Instantly share code, notes, and snippets.

@jshawl
Created December 6, 2019 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jshawl/979bf302bebe41815dc8b3759571a3a5 to your computer and use it in GitHub Desktop.
Save jshawl/979bf302bebe41815dc8b3759571a3a5 to your computer and use it in GitHub Desktop.
version: '3'
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: mysql
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
volumes:
db_data:
SELECT
accounts.id,
lasts.some_number AS last_number,
biggests.some_number AS biggest_number
FROM accounts
INNER JOIN accounts_data AS lasts
ON lasts.id = (
SELECT
MAX(id)
FROM accounts_data
WHERE accounts_data.accounts_id = accounts.id
)
INNER JOIN (
SELECT
MAX(some_number) AS some_number,
accounts_id
FROM accounts_data
GROUP BY accounts_id
) biggests
ON biggests.accounts_id = accounts.id
GROUP BY accounts.id;
-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/
--
-- Host: db
-- Generation Time: Dec 06, 2019 at 12:43 AM
-- Server version: 5.7.24
-- PHP Version: 7.2.8
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `example`
--
-- --------------------------------------------------------
--
-- Table structure for table `accounts`
--
CREATE TABLE `accounts` (
`id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `accounts`
--
INSERT INTO `accounts` (`id`) VALUES
(1),
(2),
(3);
-- --------------------------------------------------------
--
-- Table structure for table `accounts_data`
--
CREATE TABLE `accounts_data` (
`id` int(11) NOT NULL,
`accounts_id` int(11) NOT NULL,
`some_number` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `accounts_data`
--
INSERT INTO `accounts_data` (`id`, `accounts_id`, `some_number`) VALUES
(1, 1, 4),
(2, 1, 7),
(3, 1, 6),
(4, 2, 8),
(5, 2, 5);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `accounts`
--
ALTER TABLE `accounts`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `accounts_data`
--
ALTER TABLE `accounts_data`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `accounts`
--
ALTER TABLE `accounts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `accounts_data`
--
ALTER TABLE `accounts_data`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment