Facebook
From Baby Mosquito, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 764
  1. .separator ","
  2.  
  3. create TABLE tab(L1 int, T TEXT, L2 INT, L3 INT, L4 INT);
  4.  
  5. .help
  6.  
  7. .import filename.txt tab
  8.  
  9. .tables  wyświetla tabele
  10.  
  11. select * from tab (limit x);   wyświetla wszystko z tabeli
  12.  
  13. .headers on  - włącza nagłówki
  14.  
  15. .width 5 20 5 5 5       szerokość
  16.  
  17. .mode column       tryb kolumny
  18.  
  19. select count(*) from tab;           sprawdza ile jest jest wierszy w tabeli
  20.  
  21.  
  22. select count (L4) from tab where strftime('%Y',T)='2007';  wypisuje ilość elementów tabeli L4 dla roku 2007
  23.  
  24.  
  25. select T,L4 from tab where strftime('%Y',T)='2007';
  26.  
  27. select strftime('%m',T), sum(L4) from tab where strftime('%Y',T) = '2007' group by strftime('%m',T);  -wypisuje sume z tabeli L4 miesiąc po miesiącu dla roku 2007
  28.  
  29. select count (distinct L1) from tab;   pokazuje ilość L1
  30.  
  31. select sum(L4) from tab where strftime('%Y', T )="2007";        ile przelewów było w 2007
  32.  
  33. as Nazwa -  zmienia nazwe tabeli
  34.  
  35. select strftime('%w',T) as dzien , sum(L4) as suma from tab group by strftime('%w',T);    - całkowita suma L4 z całego pliku dla każdego dnia tygfodnia
  36.  
  37.  
  38. .save nazwa
  39. .quit
  40.  
  41. sqlite 3 nazwa
  42.  
  43. insert into nazwa_tabeli distinct ddd,eee from nazwa_tabeli;    - dodaje z jednej tabeli do drugiej
  44.  
  45. drop table nazwa;   -  usuwa tabele
  46.  
  47.  
  48. select strftime('%w',DATA),count(*) from BANKOMACIKI group by  strftime('%w',DATA);     -  ile razy byl uzywany bankomat kazdego dnia
  49.  
  50. .restore BANKOMATKI
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. mysql  14.11.14
  58.  
  59. set @liczba=2/3; //zmienna uzytkownika
  60. select @liczba;
  61. show variables;  //pokazuje zmienne mysql
  62.  
  63.  
  64. wcześniej użyć use baza1;
  65. select * from city where name = "Krakow";
  66. select * from city where name = "Krakow"\G;
  67.  
  68. select * from city where name like  "Kra%";  //%zastepuje dowolny lancuch znakow, szukamy miast z Kra w nazwie
  69.  
  70.  
  71. \T H:/cos/costam.txt    //otwiera plik
  72.  
  73. tutaj operacje ktore zapisuje do pliku...
  74.  
  75. \t    //zamyka plik tadam
  76.  
  77. \s wyświetla informacje ciekawe bardzo  jakiej bazy uzywamy itd
  78.  
  79. select name, lifeexperiemcy, REPEAT("*", lifeexperiency) from country where continent="Asia";
  80.  
  81.  
  82.  
  83. select name, LifeExpectancy, REPEAT("*", LifeExpectancy) from country where continent = "Asia";
  84.  
  85. select name, 1000000*gnpold/population as GNPPC_old,
  86. 1000000*gnp/population as GNPPP_new, floor(((100*1000000*gnp/population)/(1000000*gnpold/population)-100)/2) as procent, repeat("*",floor(GNP*100/GNPold-100)/2),  from country where continent = "Europe" and GNP is not null and GNPold is not null;
  87.  
  88.  
  89. 21.11.14
  90.  
  91. SELECT name, max(100000*gnp/population) from country
  92.  
  93. select continent, max(100000*gnp/population) from country group by continent
  94.  
  95.  
  96. zapisywanie do zmiannej
  97. select max(1000000*gnp/population)from country int @maxgnp
  98.  
  99.  
  100. select name, floor(lifexpetancy/10) from country order by 2 desc limit 10
  101.  
  102.  
  103. i jak uruchomić skrypt:
  104. umieszczamy w folderze z binarnymi i \.skrypt7.sql
  105.  
  106.  
  107.  
  108. 28.11.14
  109.  
  110. dalej database  world  w mysql
  111.  
  112. kwartyle populacja przez powierzchnie kraju
  113.  
  114.  
  115. select * from country limit 1\G  
  116.  
  117. select population/surfacearea from country limit 1\G  
  118.  
  119. select code, population/surfacearea from country limit 10
  120.  
  121. select code, population/surfacearea from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc);
  122.  
  123. select name,code, round(population/surfacearea,2) as dupa from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc) limit 117;
  124.  
  125. ten set mi nie działa nie wiem czemu :(
  126.  
  127. set @q2=select name,code, round(population/surfacearea,2) as dupa from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc) limit 117;
  128.  
  129.  
  130. napisz procedurę która nazywa się ttLiveEx (temporary table life excośtam) ma przyjmować dwa parametry tekstowe (dwa kody) np. 'Rus' 'Pol'. w wyniku ma być tabela tymczasowa z trzema kolumnami. zawartością mają być wszystkie kraje od rosji do polski uporządkowane według oczekiwanej średniej długości życia. kod pierwszego kraju gdzie się krócej życje i kod drugiego kraju gdzie się dłużej zyje i wszystkie między nimi.
  131.  
  132. delimiter //    (bo jakbysmy dali ; to chcialby sie wykonać)
  133.  
  134.  
  135. create procedure tt_lifeEx(IN p1 char(3), IN p2 char(3))
  136.  
  137. begin
  138. select round(lifeexpectancy * 10) from country where code=p1 into @poczatek;
  139. select round(lifeexpectancy * 10) from country where code=p2 into @koniec;
  140.  
  141. drop table if exists lifeex;
  142. create temporary table lifeex as
  143. (select code, name, lifeexpectancy from country where round(lifeexpectancy*10)
  144. between @poczatek and @koniec order by 3);
  145. end#
  146.  
  147. delimiter ;
  148.  
  149. source skrypt4a.txt
  150. call tt_lifeEx('RUS','POL');
  151. select * from lifeex
  152.  
  153.  
  154. jesli istnieje to  drop procedure tt_lifeex;
  155.  
  156.  
  157. skrypt7.sql
  158. 2.0 KB
  159.  
  160.  
  161.