Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql last year

SELECT * FROM my_table
WHERE YEAR(my_date) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR));
Comment

mysql last date

-- Max date for each model:
SELECT model, max(date) FROM models GROUP BY model;
-- All models matching the max date of the entire table:
SELECT model, date FROM models WHERE date IN (SELECT max(date) FROM models);
-- Same with model details:
SELECT d.model, d.date, d.color, d.etc FROM models d
WHERE d.date IN (SELECT max(d2.date) FROM models d2 WHERE d2.model=d.model);
-- Faster with MySQL 8.0+
SELECT model, date, color, etc FROM (SELECT model, date, color, etc, 
  max(date) OVER (PARTITION BY model) max_date FROM models) predoc 
WHERE date=max_date;
Comment

PREVIOUS NEXT
Code Example
Sql :: sql rename column 
Sql :: sql server date format dd/mm/yyyy 
Sql :: mysql alter decimal precision 
Sql :: create table with select 
Sql :: sql like 
Sql :: sql update all rows 
Sql :: uppercase and lowercase in sql 
Sql :: sql update from different table 
Sql :: oracle alter table delete column 
Sql :: mysql alter table modify column 
Sql :: random record using order by rand() mysql 
Sql :: how to search date in sql query 
Sql :: mysql order by desc null last 
Sql :: sql decimal to 2 places 
Sql :: sql create index 
Sql :: insert query in ci 
Sql :: mysql start command 
Sql :: null column to 0 in mysql 
Sql :: SQL loop with cursor 
Sql :: mysql add root password 
Sql :: random name function in mysql for nvarchar 
Sql :: get value from a table an insert it with other values in another table sql 
Sql :: mysql trim 
Sql :: select row from mysql where date more than 30 days 
Sql :: date between in mysql 
Sql :: sql count null 
Sql :: sql column contains special character 
Sql :: select if then postgresql 
Sql :: mysql drop database 
Sql :: syntaxerror unexpected identifier mysql 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =