Home > MySQL > SQL cheatsheet.

SQL cheatsheet.

My sql

SELECT x.a
FROM
( SELECT ‘1’ AS a
UNION ALL
SELECT ‘2’
UNION ALL
SELECT ‘3’
) x
WHERE a NOT IN
( SELECT knr FROM table1 )

SELECT t.CHANNEL
, COUNT(*) / SUM(grp.TotalCount)
FROM my_table t
JOIN
( SELECT LOC_CODE
, COUNT(*) TotalCount — or is it perhaps?:
— COUNT(DISTINCT CHANNEL)
FROM my_table
GROUP BY LOC_CODE
) grp
ON grp.LOC_CODE = t.LOC_CODE
GROUP BY t.CHANNEL

My delete:

DELETE
FROM table
WHERE id IN
( SELECT id
FROM table
WHERE obsolete = 1
ORDER BY id
FETCH FIRST 100000 ROWS ONLY
)

Advertisements
Categories: MySQL
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: