SQL Commands
SQL Commands
===============================================================
=====================================================
=============================================================
INSERT IGNORE INTO """+DBNAME2+""".auth_user select """+DBNAME1+""".auth_user.*
from """+DBNAME1+""".auth_user left join """+DBNAME2+""".auth_user on
"""+DBNAME1+""".auth_user.id = """+DBNAME2+""".auth_user.id where
"""+DBNAME2+""".auth_user.id is null;
=============================================================
alter table `dev_qa_db`.`dashboard_compositekey` add created_on timestamp NOT NULL
DEFAULT CURRENT_TIMESTAMP;
SELECT group_concat(column_name)
FROM information_schema.columns
WHERE table_name = 'dashboard_transactions'
AND table_schema = 'lowinfood_dev';
=========================================================
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table dev_qa_db_1.dashboard_compositekey;
SET FOREIGN_KEY_CHECKS = 1;
=================================================
**********************
SET FOREIGN_KEY_CHECKS = 0;
insert into dev_qa_db_1.dashboard_compositekey(id ,customer_id, product_id, store_id,
client_id)
select * from qa_db.dashboard_compositekey;
SET FOREIGN_KEY_CHECKS = 1;
**********************
SET FOREIGN_KEY_CHECKS = 0;
SET FOREIGN_KEY_CHECKS = 1;
===============================================
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table lowinfood_dev.dashboard_products;
TRUNCATE table lowinfood_dev.dashboard_transactions;
TRUNCATE table lowinfood_dev.dashboard_promotion;
TRUNCATE table lowinfood_dev.dashboard_promotion_product_store_info;
SET FOREIGN_KEY_CHECKS = 1;
===========================================
CREATE TABLE `dev_qa_db`.`prediction_staging_temp` (
`id` INT NULL,
`prod` INT NULL,
`tsnow` DATETIME NULL,
`tsforecast` DATETIME NULL,
`forecast` DOUBLE NULL,
`model` VARCHAR(255) NULL,
`experiment` VARCHAR(255) NULL,
`prediction_date` DATETIME NULL);
============================================================
=======================================================
=====================================================================
==============================================================
SELECT distinct ArticleId, NameLongArticle FROM dev_qa_db_1.staging_16_12_21 where
ArticleId in
(25893, 31331, 31376, 31374, 31379, 31377, 31375, 31369, 31378, 31335, 31370, 31360,
31338, 31336, 31334, 31332, 31339, 31337, 31333, 31340, 31269, 31346, 31342, 31329,
31280, 31343, 31310, 31279, 31278, 31277, 31276, 29936, 31264, 31268, 31295, 31266,
31293, 31298, 31291, 31296, 31267, 31294, 31299, 31265, 31292, 31297, 31316, 31283,
31282, 31252, 31249, 31229, 31230, 31227, 31225, 31226, 31219, 31215, 31171, 31169,
31167, 31172, 31170, 31168, 31189, 31187, 31178, 19959, 20135, 19958)
order by ArticleId;
================================================
Made by me
select count(*)
from qa_db.dashboard_predictions a
left join qa_db.dashboard_predictions b on
a.compositeKey_id = b.compositeKey_id and
a.tsnow = b.tsnow and
a.tsforecast = b.tsforecast and
a.prediction_value = b.prediction_value and
a.product_id = b.product_id and
a.store_id = b.store_id
where b.id is not null;
==================================================
select count(name) as cnt from qa_db.dashboard_products where name is not null; -- 15674
======================================================
===========================================
SELECT DISTINCT id
FROM dev_qa_db_1.dashboard_products
left join dev_qa_db_1.staging_20_12_21
on dev_qa_db_1.dashboard_products.id = dev_qa_db_1.staging_20_12_21.ArticleId
where dev_qa_db_1.dashboard_products.name is null GROUP BY ArticleId;
======================================
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE `foresightee_repository_prod`.`dashboard_transactiontemp`;
SET FOREIGN_KEY_CHECKS = 1;
============================================
============================================================
SELECT distinct da.product_id from qa_db.dashboard_assortment_products da
join qa_db.dashboard_products dp
on dp.id = da.product_id
where store_description like '%Aldi%' ;
===========================================================
INSERT INTO `foresightee_repository_dev`.`rep_schema_config` (`name`, `hostname`,
`username`, `password`, `type`) VALUES ('wallmart', 'abcdef', 'admin', 'foresightee',
'staging');
========================================================
For checking multiple values in
SELECT
col1, col2,..., COUNT(*)
FROM
table_name
GROUP BY
col1,
col2,
...
HAVING
(COUNT(col1) > 1) AND
(COUNT(col2) > 1) AND
==================================================================
===================================
To check Promotion for ald onlyi
update dev_qa_db_1.dashboard_transactions
set created_on = '2022-02-07 08:03:00',
last_modified_on = '2022-02-07 08:03:00'
where transaction_date = '2022-02-06' and store_id in (1,2,3,6,7,290,772);
================================================================
Create table in AWS Redshift with auto increment id and insert query
create table s3_file_log(
id bigint identity(1, 1),
file_name varchar(250),
created_on datetime)
copy s3_data_tmp
from 's3://revealera-redshift-uploads/input_to_rds.json'
credentials 'aws_iam_role=arn:aws:iam::713992711280:role/redshifts3'
region 'us-east-2'
json 's3://revealera-redshift-uploads/input_to_rds_jsonpath.json';
====================================================================