You are on page 1of 3

SKN MYSQL QUERIES

FOR RI BOXES
Evaluated Resource Estimates and Company Valuations

SELECT DISTINCT companies.id,companies.name ,


if((companies.exchange ='TSX VENTURE'),concat('(',companies.symbol, '.V)'),
concat('(',companies.symbol, '.T)')) as 'Exchange',companies.price,
companies.price,companies.high_52,companies.low_52,companies.market_cap,
projects.name,projects.id,commodity_changes.commodity_id,commodity_changes.id
FROM companies ,projects ,commodity_changes
WHERE commodity_changes.project_id=projects.id
AND projects.company_id=companies.id ORDER BY commodity_changes.date
DESC LIMIT 6

USING JOINS

SELECT DISTINCT companies.id,companies.name,if(companies.exchange='TSX


VENTURE',CONCAT('(',companies.symbol,'.V)'),CONCAT('(',companies.symbol,'.T)'))
AS EXNG,companies.low_52,projects.id,projects.name,commodity_changes.id FROM
commodity_changes INNER JOIN projects ON
commodity_changes.project_id=projects.id INNER JOIN companies ON
projects.company_id=companies.id ORDER BY commodity_changes.date DESC LIMIT
6;

Latest TSX Financings

SELECT DISTINCT companies.id,companies.name,


if((companies.exchange ='TSX VENTURE'),concat('(',companies.symbol, '.V)'),
concat('(',companies.symbol, '.T)')) as 'Exchange',companies.price,
companies.high_52,companies.low_52,companies.market_cap,financings.date,
financings.how_much,financings.status,financings.purpose,financings.id
FROM financings,companies
WHERE financings.company_id=companies.id
ORDER BY financings.created_at DESC LIMIT 6

Delete unused projects in projects table

DELETE FROM projects WHERE company_id NOT IN (SELECT id FROM companies


WHERE id =projects.company_id);
News count script (MARKET WIRE AND CNW)

For Marketwire

SELECT companies.id,companies.name,count(news.id)
FROM companies
INNER JOIN news
ON companies.id=news.company_id
WHERE news.source='Marketwire' AND news.date BETWEEN "2009-10-17" AND
"2010-02-16"
GROUP BY companies.id ;

Total count for For Marketwire

SELECT * FROM `news` where source='Marketwire' and date BETWEEN "2009-10-


17" AND "2010-02-16";

For CNW Group

SELECT companies.id,companies.name,count(news.id)
FROM companies
INNER JOIN news
ON companies.id=news.company_id
WHERE news.source='CNW Group' AND news.date BETWEEN "2009-10-17" AND
"2010-02-16"
GROUP BY companies.id ;

Total count for CNW Group

SELECT * FROM `news` where source='CNW Group' and date BETWEEN "2009-10-
17" AND "2010-02-16";

Country Update Script

use skn_development;
ALTER TABLE managements ADD seq_no INT(11) Default 1;

use skn_development;
UPDATE companies SET country='USA' WHERE country='United States';
UPDATE projects SET country='USA' WHERE country='United States';
UPDATE provinces SET country='USA' WHERE country='United States';
UPDATE users SET country='USA' WHERE country='United States';
delete from countries where name='United states';

SKN seq_no(management) update query

DROP TABLE IF EXISTS `skn_development`.`tmp_managements`;


CREATE TABLE `skn_development`.`tmp_managements` (
`id` int(11) NOT NULL ,
`company_id` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`role` varchar(255) DEFAULT NULL,
`seq_no` int(11) DEFAULT NULL AUTO_INCREMENT,
PRIMARY KEY (`seq_no`)
);

Insert into tmp_managements (id, company_id)


SELECT id,company_id FROM managements order by company_id;

DROP TABLE IF EXISTS `tmp_mgt`;


create table tmp_mgt select * from tmp_managements group by company_id;

update tmp_managements, tmp_mgt,managements set managements.seq_no =


(tmp_managements.seq_no - tmp_mgt.seq_no) + 1
where (tmp_managements.id = managements.id and tmp_managements.company_id =
tmp_mgt.company_id)