Pages
Labels
- Bisnis (1)
- CIT Scripts - Financore (5)
- Cokelat (3)
- MySQL (2)
- PHP (23)
- PT Comment Indonesia (10)
- SQL Query (2)
- SQL Server 2000 (4)
- SQL Server 2005 (4)
- Tips - Tricks Cokelat (2)
Archives
Link List
- Code Igniter Indonesia
- MySQL Reference Manuals
- MySQL Tutorial
- SQL Developer
- 9 Useful jQuery Calendar and Date Picker Plugins For Web Designers
- 10 Powerful AJAZ jQuery File Uploaders
- 35 Useful jQuery Plugins for Slideshows, Graphs and Text Effects
- 30 jQuery Calendar Date Picker Plugins
- jQuery
- Web Developers Notes
- SQL Copy MySQL Table
- Natural Cooking Club Indonesia
- Aneka Resep Praline - Sedap Sekejap
- Resep Cokelat
- Pastry and Bakery
- Peluang Bisnis Hotspot
- Billing Hospot
- JpGraph
- Zend Developer Zone
- MySQL Tutorials and Others
- W3 School
- Open Source Projects
Untuk meng-update field suatu tabel dengan isi field dari tabel lain bisa menggunakan perintah :
UPDATE ... SELECT ....
Contoh nya sbb. Field PAJAK dari tabel TMP_RCOM_ALLOWANCE_ICD akan di-update dengan isi field PAJAK dari tabel TMP_PAJAK_KOMISI.
Perintahnya adalah sbb :
update TMP_RCOM_ALLOWANCE_ICD
set PAJAK = b.PAJAK
from TMP_RCOM_ALLOWANCE_ICD a, TMP_RCOM_PAJAK_KOMISI b
where a.V_AGENT_CODE = b.KODEAGEN and b.PERIODE = '20121215' and b.KETERANGAN = 'ALLOWANCE-ICD'
"
$filenm = fopen("U-THCQ-DataItemH1-1209281400.mm", "r");
// Read line by line until end of file
while(!feof($filenm)) {
$filename = fgets($filenm);
$pisah = explode(";", $filename);
$no_sj = $pisah[0];
$tgl_sj = $pisah[1];
$no_do = $pisah[2];
$tgl_do = $pisah[3];
//echo fgets($filenm) . "
";
echo $no_sj . " - " . $tgl_sj . " - " . $no_do . " - " . $tgl_do . "
";
}
fclose($filenm);
?>
"
Nama text file yang dibaca adalah : U-THCQ-DataItemH1-1209281400.mm.
Output yang dihasilkan sebagai berikut :
CBR150RC(IN)M/T - BK - BLACK - CBR 150R
CBR150RC(IN)M/T - OH - ORANGE HITAM - CBR 150R
CBR150RC(IN)M/T - PM - PUTIH MERAH - CBR 150R
CBR150RC(IN)M/T - RD - RED - CBR 150R
CBR150RC(IN)RM/T - OH - ORANGE HITAM - CBR 150R
Labels: PHP
$bulan = "02";
$tahun = "2009";
$lastday= date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date($bulan).'/01/'.date($tahun).' 00:00:00'))));
echo "Tanggal terakhir dari bulan $bulan $tahun adalah $lastday
";
$exlast = explode("-", $lastday);
//ambil nama hari dari tgl terakhir
$cekhari = mktime(0,0,0,date($exlast[1]),date($exlast[2]),date($exlast[0]));
$tglcekhari = date("Y-m-d", $cekhari);
$hari = date("D", $cekhari);
echo "jatuh pada hari \"$hari\"
";
echo "Tgl yang diambil adalah : ".CekLastDay($lastday,0);
function CekLastDay($X,$Z) {
$Extgl = explode("-",$X);
$M = mktime(0,0,0,date($Extgl[1]),date($Extgl[2])-$Z,date($Extgl[0]));
$Mtgl = date("Y-m-d", $M);
$Mhari = date("D", $M);
if($Mhari=="Sat" or $Mhari=="Sun") {
return CekLastDay($Mtgl,1);
//echo "sini $Mtgl
";
} else
return $Mtgl;
}
?>
Tampilan outputnya sebagai berikut :
Tanggal terakhir dari bulan 02 2009 adalah 2009-02-28
jatuh pada hari "Sat"
Tgl yang diambil adalah : 2009-02-27
Labels: PHP
Untuk memanggilnya menggunakan fungsi : terbilangs.
-----
function terbilang($angka) {
// pastikan kita hanya berususan dengan tipe data numeric
$angka = (float)$angka;
// array bilangan
// sepuluh dan sebelas merupakan special karena awalan 'se'
$bilangan = array(
'',
'satu',
'dua',
'tiga',
'empat',
'lima',
'enam',
'tujuh',
'delapan',
'sembilan',
'sepuluh',
'sebelas'
);
// pencocokan dimulai dari satuan angka terkecil
if ($angka < 12) {
// mapping angka ke index array $bilangan
return $bilangan[$angka];
} else if ($angka < 20) {
// bilangan 'belasan'
// misal 18 maka 18 - 10 = 8
return $bilangan[$angka - 10] . ' belas';
} else if ($angka < 100) {
// bilangan 'puluhan'
// misal 27 maka 27 / 10 = 2.7 (integer => 2) 'dua'
// untuk mendapatkan sisa bagi gunakan modulus
// 27 mod 10 = 7 'tujuh'
$hasil_bagi = (int)($angka / 10);
$hasil_mod = $angka % 10;
return trim(sprintf('%s puluh %s', $bilangan[$hasil_bagi], $bilangan[$hasil_mod]));
} else if ($angka < 200) {
// bilangan 'seratusan' (itulah indonesia knp tidak satu ratus saja? :))
// misal 151 maka 151 = 100 = 51 (hasil berupa 'puluhan')
// daripada menulis ulang rutin kode puluhan maka gunakan
// saja fungsi rekursif dengan memanggil fungsi terbilang(51)
return sprintf('seratus %s', terbilang($angka - 100));
} else if ($angka < 1000) {
// bilangan 'ratusan'
// misal 467 maka 467 / 100 = 4,67 (integer => 4) 'empat'
// sisanya 467 mod 100 = 67 (berupa puluhan jadi gunakan rekursif terbilang(67))
$hasil_bagi = (int)($angka / 100);
$hasil_mod = $angka % 100;
return trim(sprintf('%s ratus %s', $bilangan[$hasil_bagi], terbilang($hasil_mod)));
} else if ($angka < 2000) {
// bilangan 'seribuan'
// misal 1250 maka 1250 - 1000 = 250 (ratusan)
// gunakan rekursif terbilang(250)
return trim(sprintf('seribu %s', terbilang($angka - 1000)));
} else if ($angka < 1000000) {
// bilangan 'ribuan' (sampai ratusan ribu
$hasil_bagi = (int)($angka / 1000); // karena hasilnya bisa ratusan jadi langsung digunakan rekursif
$hasil_mod = $angka % 1000;
return sprintf('%s ribu %s', terbilang($hasil_bagi), terbilang($hasil_mod));
} else if ($angka < 1000000000) {
// bilangan 'jutaan' (sampai ratusan juta)
// 'satu puluh' => SALAH
// 'satu ratus' => SALAH
// 'satu juta' => BENAR
// @#$%^ WT*
// hasil bagi bisa satuan, belasan, ratusan jadi langsung kita gunakan rekursif
$hasil_bagi = (int)($angka / 1000000);
$hasil_mod = $angka % 1000000;
return trim(sprintf('%s juta %s', terbilang($hasil_bagi), terbilang($hasil_mod)));
} else if ($angka < 1000000000000) {
// bilangan 'milyaran'
$hasil_bagi = (int)($angka / 1000000000);
// karena batas maksimum integer untuk 32bit sistem adalah 2147483647
// maka kita gunakan fmod agar dapat menghandle angka yang lebih besar
$hasil_mod = fmod($angka, 1000000000);
return trim(sprintf('%s milyar %s', terbilang($hasil_bagi), terbilang($hasil_mod)));
} else if ($angka < 1000000000000000) {
// bilangan 'triliun'
$hasil_bagi = $angka / 1000000000000;
$hasil_mod = fmod($angka, 1000000000000);
return trim(sprintf('%s triliun %s', terbilang($hasil_bagi), terbilang($hasil_mod)));
} else {
return 'Wow...';
}
}
function koma($x)
{
$x = stristr($x,'.');
$angka = array('nol','satu','dua','tiga','empat','lima','enam','tujuh','delapan','sembilan');
$temp = '';
$pjg = strlen($x);
$pos = 1;
while($pos < $pjg)
{
$char = substr($x,$pos,1);
$pos++;
$temp .= ' '.$angka[$char];
}
return $temp;
}
function terbilangs ($x)
{
if($x<0 p="p"> {
$hasil = 'minus '.trim(terbilang($x));
}
else
{
$poin = trim(koma($x)) ;
$hasil = trim(terbilang($x));
}
if($poin)
{
$hasil = ucwords($hasil).' Koma '.ucwords($poin);
}
else
{
$hasil = ucwords($hasil);//.' koma '.ucwords($poin);;
}
return $hasil;
}
?>
0>
Labels: PHP
ALTER FUNCTION f_agent_name_by_agentcode
(
@param1 varchar(50)
)
RETURNS varchar(50)
AS
BEGIN
DECLARE @name_desc as varchar(50)
select @name_desc = a.V_NAME
from GNMT_CUSTOMER_MASTER a, AMMM_AGENT_MASTER b
where a.N_CUST_REF_NO = b.N_CUST_REF_NO and b.V_AGENT_CODE = @param1
RETURN @name_desc
END
GO
Sedangkan untuk memanggil fungsi tersebut adalah sebagai berikut :
select dbo.f_agent_name_by_agentcode('A0027258') as hasil
Mudah bukan?
Labels: SQL Query
Pada dasarnya membuat Fungsi sama dengan membuat Stored Procedure. Perbedaannya adalah, dalam Stored Procedure tidak mengembalikan sebuah nilai, sedangkan dalam Fungsi, akan mengembalikan suatu nilai. Berikut contohnya : ALTER FUNCTION f_agent_name_by_agentcode ( @param1 varchar(5) ) RETURNS varchar(50) AS BEGIN DECLARE @name_desc as varchar(50) select @name_desc = a.V_NAME from GNMT_CUSTOMER_MASTER a, AMMM_AGENT_MASTER b where a.N_CUST_REF_NO = b.N_CUST_REF_NO and b.V_AGENT_CODE = @param1 RETURN @name_desc END GO Sedangkan untuk memanggil fungsi tersebut adalah sebagai berikut : select dbo.f_agent_name_by_agentcode('A0027258') as hasil Fungsi f_agent_name_by_agentcode akan mencari nama agent dengan kode agent 'A0027258', sehingga akan mengembalikan hasil sebagai berikut : SITI RAHMAWATI, DRA Mudah bukan?
Labels: SQL Server 2005
Berikut ini saya akan mencoba untuk mengakses data di tabel Customer yang sudah tersedia di database MySQL dengan menggunakan PHP. Procedure ini akan mem-passing 1 buah parameter yaitu Customer Id nya.
Pertama sya membuat procedure untuk membuat query nya sebagai berikut :
CREATE PROCEDURE `usp_testCustomer3`(
IN CustId varchar(18)
)
BEGIN
select customer_id, customer_name
from customer
where customer_id = CustId
group by customer_id, customer_name;
END
Setelah procedure tercipta, kita coba akses procedure tersebut dengan PHP. Program PHP tersebut saya buat sebagai berikut :
<html>
<body>
<h1>Parsing parameter to a stored procedure</h1>
<pre>
<?php
$mysql = mysql_connect('localhost', 'root', 'triadpass', false, 65536);
mysql_select_db('new_ccrm');
$query = "CALL usp_testCustomer3('01080800051139')";
$result=mysql_query($query) or die(mysql_error());
if ($result)
{
while ($rows=mysql_fetch_array($result))
{
echo trim($rows['customer_id']) . " - " . trim($rows['customer_name']) . "<br>";
}
mysql_free_result($result);
}
mysql_close($mysql)
?>
</pre><br>
This demonstration shows a stored procedure to which a parameter has
been passed which is passed in turn into the select query.
</body>
</html>
Setelah itu saya jalankan script PHP tersebut, sehingga outputnya adalah sebagai berikut :
Parsing parameter to a stored procedure
01080800051139 - R. HESTI ENDANG SIREGAR
This demonstration shows a stored procedure to which a parameter has been passed which is passed in turn into the select query.
Nah, ternyata tidak sulit kan membuatnya? Selamat berkreasi dengan procedure-procedure yang lain.
Labels: PHP
Untuk mengakses data pada database biasanya kita menggunakan query biasa di program, baik itu menggunakan ASP, VB, .Net, PHP atau bahasa pemrograman apapun.
Kali ini saya ingin mencoba untuk mengakses data pada database MySQL dengan memanfaatkan Procedure dan dipanggil menggunakan bahasa pemrograman PHP.
Dengan menggunakan tabel Customer yang sudah tersedia, saya mencoba untuk membuat procedure tanpa parameter untuk menampilkan field Customer Id dan Customer Name.
Pertama saya buat procedurenya dahulu sebagai berikut :
CREATE PROCEDURE `ups_testCustomerNonParam`()
BEGIN
select * from customer
order by customer_id
limit 25;
END
Limit 25 disini maksudnya saya hanya ingin menampilkan sebanyak 25 record saja, karena total keseluruhannya bisa mencapai ratusan ribu reord.
Setelah Procedure ter-create lalu kita buat program PHP untuk memanggil procedure tersebut.
<html>
<body>
<h1>Access Data from a stored procedure</h1>
<pre>
<?php
$mysql = mysql_connect('localhost', 'root', 'triadpass', false, 65536);
mysql_select_db('new_ccrm');
$query = "CALL ups_testCustomerNonParam()";
$result=mysql_query($query) or die(mysql_error());
if ($result)
{
while ($rows=mysql_fetch_array($result))
{
echo trim($rows['customer_id']) . " - " . trim($rows['customer_name']) . "<br>";
}
mysql_free_result($result);
}
mysql_close($mysql)
?>
</pre><br>
This demonstration shows a stored procedure to which a parameter has
been passed which is passed in turn into the select query.
</body>
</html>
Nah, setelah itu kita bisa akses program tersebut dan outputnya adalah sebagai berikut :
Access Data from a stored procedure
123 - AMEL
*10120310319990000 - Jeny
0001 - ATIK
0001 - CHINTIA
0001 - ELOK
0001 - EVI
0001 - IREN
0001 - MILA
0001 - NURLAILA
0001 - RATNA
0001 - RODATUL
0001 - SUMIYATI
0001 - TAMY
0001 - VERONIKA
0001 - WINIE
0001 - YANTI
01080800030002 - TJONG NURSANA
01080800030003 - MARIAMAN
01080800030004 - LENA
01080800030005 - HETI
01080800030006 - FITRI
01080800030007 - RISMA TUMORANG
01080800030008 - HETI
01080800030009 - ASIH
01080800030010 - ELI
Mudah bukan caranya? Untuk topik berikutnya, saya akan coba membuat sebuah program PHP singkat untuk mengakses procedure dengan menggunakan parameter.
Labels: PHP
Pada prinsipnya untuk membuat Stored Procedure dengan 1 atau lebih parameter sama saja. Untuk lebih jelasnya kita coba untuk membuat Stored Procedure nya terlebih dahulu.
CREATE PROCEDURE `usp_testCustomer2`(
out cu1 varchar(18),
out cu2 varchar(18)
)
BEGIN
select min(customer_id) as minimum, max(customer_id) as maksimum
into cu1, cu2
from customer;
END
Lalu untuk menjalankan Stored Procedured tersebut sebagai berikut :
set @cust1 = '123';
set @cust2 = 'phonep';
CALL usp_testCustomer2(@cust1, @cust2);
select @cust1, @cust2;
Labels: MySQL
Berikut ini catatan untuk membuat Stored Procedure di MySQL dan memanggil Stored Procedured tersebut.
Pertama kita buat Stored Procedure nya sbb :
CREATE PROCEDURE `usp_testCustomer`(IN custId varchar(18))
BEGIN
select customer_id, customer_name, count(*) as jumlah
from customer
where customer_id = custID
group by customer_id, customer_name;
END
Setelah itu kita eksekusi Stored Procedure tersebut dengan cara :
set @customer = '01080800051139';
call usp_testCustomer(@customer);
Output yang dihasilkan sbb :
customer_id customer_name jumlah
01080800051139 R. HESTI ENDANG SIREGAR 1
Bila kita ingin parameter yang di-input juga berfungsi sebagai parameter untuk output, caranya adalah sebagai berikut.
Pertama kita buat Stored Procedure nya terlebih dahulu :
CREATE PROCEDURE `usp_testCustomer1`(INOUT custId varchar(18))
BEGIN
DECLARE custId1 VARCHAR(18) DEFAULT custId;
select customer_id, customer_name, count(*) as jumlah
from customer
where customer_id = custID
group by customer_id, customer_name;
set custId = custId1;
END
Setelah itu kita jalankan Stored Procedure tersebut :
set @customer = '01080800051139';
call usp_testCustomer1(@customer);
select @customer;
Output yang dihasilkan sbb :
customer_id
01080800051139
Labels: MySQL
Labels: PHP
Beberapa fungsi php yang berhubungan dengan url adalah sebagai berikut :
<?php
echo "Mendapatkan path dari file yang aktif" . "<br>";
echo $PHP_SELF . "<br><br>";
$url=parse_url("http://localhost/ford/edit_employee.php?kode_employee=5");
echo "Mendapatkan url scheme" . "<br>";
echo $url[scheme] . "<br><br>";
echo "Mendapatkan url host" . "<br>";
echo $url[host] . "<br><br>";
echo "Mendapatkan url path" . "<br>";
echo $url[path] . "<br><br>";
echo "Mendapatkan url query" . "<br>";
echo $url[query] . "<br><br>";
echo "Mendapatkan nama dari file yang aktif" . "<br>";
echo basename($PHP_SELF) . "<br><br>";
echo "Mendapatkan referer" . "<br>";
echo $HTT
Output yang dihasilkan adalah sbb :
Mendapatkan path dari file yang aktif
/latihan/alamat_url_1.php
Mendapatkan url scheme
http
Mendapatkan url host
localhost
Mendapatkan url path
/ford/edit_employee.php
Mendapatkan url query
kode_employee=5
Mendapatkan nama dari file yang aktif
alamat_url_1.php
Mendapatkan referer
Labels: PHP
str_replace : menghapus semua karakter spasi
syntax :
str_replace("string_expression1", "string_expression2", "string_expression3")
Contoh :
<?php
$text = "Jakarta Adalah Ibukota Indonesia";
$hasil = str_replace(" ","", $text);
$rawstring = "Your replacement is a pleasure to have!";
$malestr = str_replace("replacement", "son", $rawstring);
echo "Sebelum = " . $text . "<br>";
echo "Sesudah = " . $hasil . "<br><br>";
echo "Sebelum : Son = " . $rawstring . "<br>";
echo "Sesudah : Son = " . $malestr . "<br>";
?>
Output :
Sebelum = Jakarta Adalah Ibukota Indonesia
Sesudah = JakartaAdalahIbukotaIndonesia
Sebelum : Son = Your replacement is a pleasure to have!
Sesudah : Son = Your son is a pleasure to have!
Labels: PHP
-- Data Position utk materna
select cu.customer_id, cu.customer_name, cu.customer_phone, pl.product_id, ch.child_expected_birthday, ca.calling_strike_id
from customer cu, calling ca, product_log pl, children ch
where cu.customer_id = ca.customer_id
and ca.validation_id = '1'
and cu.customer_id = pl.customer_id
and cu.customer_id = ch.customer_id
and pl.product_id = 'materna'
and pl.consumed_by = cu.customer_id
and cu.followup_status = '1'
and cu.loyalty1_by <> " "
-- and ca.calling_strike_id <> '12'
and ca.calling_result_id = '1'
and ca.calling_for_id = '3'
-- and ca.calling_strike_id in ('4','5','10','11','13','14','15')
and (select ca2.calling_strike_id from calling ca2 where ca2.customer_id = cu.customer_id and ca2.phone_date = (select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1) not in ('12', '17')
and ch.child_expected_birthday <> '0000-00-00'
and cu.submit_date <= curdate()
-- and cu.customer_id = '01080800030023'
group by cu.customer_id
order by cu.customer_id
-- limit 100
Labels: PT Comment Indonesia
-- Data Position Anak dgn Produk
-- select aa.umur_anak, aa.product_id, count(aa.umur_anak) as jumlah
-- from
-- (
select ch.child_id, cu.customer_id, ch.child_name, ch.child_birthday,
-- PERIOD_DIFF(DATE_FORMAT('2010-11-30','%Y%m'),DATE_FORMAT(ch.child_birthday,'%Y%m')) as umur_anak,
((datediff(curdate(), ch.child_birthday)) / 30) as umur_anak,
-- (case when PERIOD_DIFF(DATE_FORMAT(curdate(),'%Y%m'),DATE_FORMAT(ch.child_birthday,'%Y%m')) between 0 and 6 then 'IF1'
-- when PERIOD_DIFF(DATE_FORMAT(curdate(),'%Y%m'),DATE_FORMAT(ch.child_birthday,'%Y%m')) between 7 and 12 then 'IF2'
-- when PERIOD_DIFF(DATE_FORMAT(curdate(),'%Y%m'),DATE_FORMAT(ch.child_birthday,'%Y%m')) between 13 and 36 then 'ESS3'
-- end) as product_id,
-- (case when ((datediff(curdate(), ch.child_birthday)) / 30) >= 0 and ((datediff(curdate(), ch.child_birthday)) / 30) <= 6 then 'IF1'
-- when ((datediff(curdate(), ch.child_birthday)) / 30) > 6 and ((datediff(curdate(), ch.child_birthday)) / 30) <= 12 then 'IF2'
-- when ((datediff(curdate(), ch.child_birthday)) / 30) > 12 and ((datediff(curdate(), ch.child_birthday)) / 30) <= 36 then 'ESS3'
-- when ((datediff(curdate(), ch.child_birthday)) / 30) > 36 then 'ESS4'
-- end) as product_id,
pl.product_id,
cl.calling_result_id,
cu.customer_address, cu.customer_phone, cu.customer_phone_2
from children ch
inner join customer cu on ch.customer_id = cu.customer_id
inner join calling cl on cl.customer_id = cu.customer_id
inner join product_log pl on pl.customer_id = cu.customer_id
where ((ch.child_birthday >= (date_sub(curdate(), interval 37 month)))
and (ch.child_birthday <= (date_sub(curdate(), interval 0 month))))
and (ch.child_birthday<> '0000-00-00' or ch.child_birthday like '0001-00-00')
and cl.validation_id='1'
and cu.followup_status = '1'
and cl.calling_result_id = '1'
and pl.consumed_by = ch.child_id
and (select ca2.calling_strike_id from calling ca2 where ca2.customer_id = cu.customer_id and ca2.phone_date = (select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1) not in ('6', '12', '16')
and pl.product_id in ('if1', 'if2', 'ess3', 'ess4')
group by ch.child_id
order by ch.child_id, ch.child_birthday
-- limit 60000,60000
-- ) aa
-- group by aa.umur_anak, aa.product_id
-- order by aa.umur_anak
Labels: PT Comment Indonesia
strcasecmp : membandingkan 2 string yang tidak case sensitive
syntax :
strcasecmp (string $str1, string $str2)
akan menghasilkan < 0 jika str1 < str2
> 0 jika str1 > str2
= 0 jika data sama
Contoh :
<?php
$kata1 = "Jakarta";
$kata2 = "jaKarta";
if (strcasecmp($kata1,$kata2) == 0)
{
echo "Kata antara " . $kata1 . " dan " . $kata2 . " sama ...";
}
else
{
echo "Kata tidak sama ...";
}
?>
Output yang dihasilkan adalah sbb :
Kata antara Jakarta dan jaKarta sama ...
Labels: PHP
select customer_id, count(*)
from calling
group by customer_id
having count(*) > 1
order by customer_id
Labels: SQL Query
select cu.customer_id as ID,cu.customer_name as NAMA,cu.customer_phone as PHONE1,cu.customer_phone_2 as PHONE2,cu.customer_address as ALAMAT, pl.product_id as PRODUK,cs.calling_strike_name,(select max(calling.phone_date)
from calling where calling.customer_id=cu.customer_id and calling.calling_target_name=pl.consumed_by) as telepon from customer cu
inner join product_log pl on pl.customer_id=cu.customer_id
inner join calling ca on ca.customer_id=cu.customer_id
inner join calling_strike cs on cs.calling_strike_id=ca.calling_strike_id
where ca.calling_strike_id='10'
and pl.product_id='lacta'
and cu.submit_date<='2010-12-09'
and pl.consumed_by=cu.customer_id
and
(select ca2.calling_strike_id from calling ca2
where ca2.customer_id = cu.customer_id
and ca2.phone_date =
(select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1)
not in ('12', '17')
group by cu.customer_id
order by cu.customer_name
Labels: PT Comment Indonesia
select aa.umur_anak, count(aa.umur_anak) as jumlah
from
(
select ch.child_id, cu.customer_id, ch.child_name, ch.child_birthday,
PERIOD_DIFF(DATE_FORMAT('2010-11-30','%Y%m'),DATE_FORMAT(ch.child_birthday,'%Y%m')) as umur_anak, cl.calling_result_id,
cu.customer_address, cu.customer_phone, cu.customer_phone_2
from children ch
inner join customer cu on ch.customer_id = cu.customer_id
inner join calling cl on cl.customer_id = cu.customer_id
where ((ch.child_birthday >= (date_sub(curdate(), interval 37 month)))
and (ch.child_birthday <= (date_sub(curdate(), interval 0 month))))
and (ch.child_birthday<> '0000-00-00' or ch.child_birthday like '0001-00-00')
and cl.validation_id='1'
and cu.followup_status = '1'
and cl.calling_result_id = '1'
and (select ca2.calling_strike_id from calling ca2 where ca2.customer_id = cu.customer_id and ca2.phone_date = (select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1) not in ('12', '17')
group by ch.child_id
order by ch.child_id, ch.child_birthday
-- limit 60000,60000
) aa
group by aa.umur_anak
order by aa.umur_anak
Labels: PT Comment Indonesia
-- Data Position utk materna
select cu.customer_id, cu.customer_name, cu.customer_phone, pl.product_id, ch.child_expected_birthday, ca.calling_strike_id
from customer cu, calling ca, product_log pl, children ch
where cu.customer_id = ca.customer_id
and ca.validation_id = '1'
and cu.customer_id = pl.customer_id
and cu.customer_id = ch.customer_id
and pl.product_id = 'materna'
and pl.consumed_by = cu.customer_id
and cu.followup_status = '1'
and cu.loyalty1_by <> " "
-- and ca.calling_strike_id <> '12'
and ca.calling_result_id = '1'
and ca.calling_for_id = '3'
-- and ca.calling_strike_id in ('4','5','10','11','13','14','15')
and (select ca2.calling_strike_id from calling ca2 where ca2.customer_id = cu.customer_id and ca2.phone_date = (select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1) not in ('12', '17')
and ch.child_expected_birthday <> '0000-00-00'
and cu.submit_date <= curdate()
-- and cu.customer_id = '01080800030023'
group by cu.customer_id
order by cu.customer_id
Labels: PT Comment Indonesia