mysql varius sentences





  1. I see all foreign keys to a table or column: SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = '<table>'
  2. Distinc values in 2 columns from 2 tables:SELECT
     SELECT DISTINCT t1.`ID_POSTULANTE` AS T1_ID_POSTULANTE FROM
      `tb_postulante` t1 INNER JOIN `aulaasignada` as t2
       ON t1.`ID_POSTULANTE` != t2.`ID_POSTULANTE`
       GROUP BY T1_ID_POSTULANTE
  3. values duplicate for one column: SELECT certificado_id_correlativo FROM t_certificado_digital group by certificado_id_correlativo having count(*) >= 2
  4. update from select: update tabla1 inner join tabla2 on tabla1.id_tabla2 = tabla2.id set tabla1.campo=tabla2.language
  5. update year sales: update sales set created_at=DATE_FORMAT(created_at, '2020-%m-%d') where YEAR(created_at) < 2020 ;
  6. update month sales: update sales set created_at=DATE_FORMAT(created_at, '%y-10-%d') where MONTH(created_at) < 10 ;
  7. update day sales: update sales set created_at=DATE_FORMAT(created_at, '%y-%m-25') where DAY(created_at) < 10 and MONTH(created_at) = 10 ;
  8. update month invertval sales: update sales set created_at=date_add(created_at, interval 1 month);
  9. insert select:
    1. INSERT INTO generic_stage.entity_items (
          client_id,
          item_type_id,
          item_id,
          action_type,
          action_result,
          marketing_flag,
          creation_timestamp
      )
      SELECT
          '300001' AS client_id,
          8 AS item_type_id,
          cg.id AS item_id,
          1 AS action_type,
          1 AS action_result,
          0 AS marketing_flag,
          NOW() AS creation_timestamp -- use NOW() for current timestamp
      FROM generic_source.item_source cg
      WHERE source_provider_id = 7;











source:

0 comentarios :

arch and manjaro temp size









create this script and run:


Terminal:
#!/bin/bash

sudo mount -o remount,size=40G,noatime /tmp
echo "Done. Please use 'df -h' to make sure folder size is increased."


source: https://gist.github.com/ertseyhan/618ab7998bdb66fd6c58
















0 comentarios :

how create service linux repeat each 10s






Terminal:
nano /etc/systemd/system/test.service


[Unit]                                                                                                                                            
Description=test_job                                                                                                                              
                                                                                                                                                  
[Service]                                                                                                                                         
Type=oneshot                                                                                                                                      
ExecStart=/usr/bin/php /tmp/run.php 




Terminal:
nano /etc/systemd/system/test.timer

[Unit]                                                                                                                                            
Description=test                                                                                                                                  
                                                                                                                                                  
[Timer]                                                                                                                                           
OnUnitActiveSec=10s                                                                                                                               
OnBootSec=10s                                                                                                                                     
                                                                                                                                                  
[Install]                                                                                                                                         
WantedBy=timers.target


Terminal:
systemctl daemon-reload

Terminal:
systemctl start test.timer

Terminal:
systemctl list-timers --all

Source:

https://unix.stackexchange.com/questions/198444/run-script-every-30-min-with-systemd


0 comentarios :