Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Joriy oydagi yozuvlar soni

+2 ovoz
66 marta ko‘rilgan
so‘radi 04 yanvar, 17 Bilmasvoy (904 bal)

Bitta jadval bor:

CREATE TABLE `items` (
    id INT(11) NOT NULL AUTO_INCREMENT,
    title VARCHAR(25) NOT NULL,
    types VARCHAR(25) NOT NULL,
    dt DATE NOT NULL,
    PRIMARY KEY (`id`)
)

types - ikki xil qiymat oladi, one va two

Joriy oy uchun quyidagi shaklda ma'lumotlarni chiqarish kerak

| id | one-types soni | two-types soni |

Mening urinishlarim:

SELECT *, COUNT(*) 
  FROM `items` 
 WHERE MONTH(dt) = MONTH(NOW()) 
   AND YEAR(dt) = YEAR(NOW()) 
 GROUP BY `types`

Ammo ishlamadi, Iltimos, shu so`rovni tuzishga yordam bersangiz.

2 Javoblar

+1 ovoz
javob berdi 04 yanvar, 17 Baron (858 bal)
tanlangan 04 yanvar, 17 Bilmasvoy
 
Eng yaxshi javob

Natijada id chiqmaydi, chunki joriy oy uchun bir nechta id bor.

1-usul:

TRANSFORM COUNT(types)
SELECT asd.dt
FROM asd
  where month(dt)=month(now())
GROUP BY asd.dt
PIVOT asd.types;

2-usul:

select dt,
  sum (iif(types='one',1,0)) as one,
  sum (iif(types='two',1,0)) as two
from asd 
where month(dt)=month(now())
group by dt

MySQL uchun:

select dt,
  SUM(if(types='one',1,0)) as one,
  SUM(if(types='two',1,0)) as two
from items 
where month(dt)=month(now())
group by dt

Shuningdek

select dt,
  SUM(case types when 'one' then 1 else 0 end) as one,
  SUM(case types when 'two' then 1 else 0 end) as two
from items 
where month(dt)=month(now())
group by dt

3-usul:

SELECT dt,
  (select count(*) as a from asd where types='one' and month(dt)=month(now())) AS one, 
  (select count(*) as b from asd where types='two' and month(dt)=month(now())) AS two
FROM asd
where month(dt)=month(now())
group by dt
izoh qoldirdi 04 yanvar, 17 Bilmasvoy (904 bal)
1-usul va 2-usul mysql da ishlamasa kerak. Siz MS SQL da qilib berdiz shekilli. 3-usul esa juda uzoq ishlarkan. teroq variant bormi?
izoh qoldirdi 04 yanvar, 17 Baron (858 bal)
2-usulni MySQL ga moslab qo'shib qo'ydim, bir ko'ring...
+1 ovoz
javob berdi 04 yanvar, 17 anorboev (124 bal)

quyidagini sinab ko'ring:

SELECT types, COUNT(*) 
  FROM items 
 WHERE MONTH(dt) = MONTH(NOW()) 
   AND YEAR(dt) = YEAR(NOW()) 
 GROUP BY types
izoh qoldirdi 04 yanvar, 17 Bilmasvoy (904 bal)
bu o`xshamadi. chunki menga 2 ta natija bitta qatorda kerak edi. bu yerda 2 ta qatorda chiqvotti

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...