Why the query is giving result while the destCurrency is not 0 - - mysql

SELECT *
FROM xyz
WHERE applyat = 'anita'
AND applyAt = 'Create'
AND country = '50'
AND dest_country = '108'
AND originCurrency = 'EUR'
AND destCurrency = 0 AND isEnable = 'Y'
AND agentID = 0
AND Module = 'abc'
ORDER BY ruleID DESC

You should add quotes as it is a varchar
SELECT * FROM xyz WHERE applyat = 'anita' AND applyAt = 'Create' AND country = '50' AND dest_country = '108' AND originCurrency = 'EUR' AND destCurrency = '0' AND isEnable = 'Y' And agentID = 0 AND Module = 'abc' ORDER BY ruleID DESC

Related

MYSQL Group by DATA NOT individually

This is My Data:
I want select data Like This ▼
I try select that in group by but is not individually data show.
and this is my code
select
date_format((select receive_contract_datetime from worklist_info where id = worklist_id), '%y.%m.%d') as receive_datetime,
(select trade_name from trade_info where id = (select worklist_trade_id from worklist_info where id = worklist_id)) as trade_name,
(select staff_name from staff_info where id =
(select account_staff_id from account_info where id =
(select worklist_account_id from worklist_info where id = worklist_id))) as worklist_writer,
date_format((select worklist_output_plan_date from worklist_info where id = worklist_id), '%y.%m.%d') as output_plan_date,
(select worklist_project_name from worklist_info where id = worklist_id) as prj_name,
worklist_sub_process_id,
count(worklist_sub_process_id),
sum(worklist_sub_state),
-- (sum(worklist_sub_process_id = 1)*2) as laser_count, worklist_sub_state
-- sum(worklist_sub_process_id = 1) as laser_count,
-- if(sum(worklist_sub_process_id = 1) > 0,count(IF(worklist_sub_process_id = 1, if(worklist_sub_state = 0,1,null), null)),-1) as laser_wait,
-- if(sum(worklist_sub_process_id = 1) > 0,count(IF(worklist_sub_process_id = 1, if(worklist_sub_state = 1,1,null), null)),-1) as laser_run,
-- if(sum(worklist_sub_process_id = 1) > 0,count(IF(worklist_sub_process_id = 1, if(worklist_sub_state = 2,1,null), null)),-1) as laser_end,
(select worklist_comment from worklist_info where id = worklist_id) as worklist_comment,
(select worklist_lot from worklist_info where id = worklist_id) as lot_number
from worklist_info_sub group by worklist_id,worklist_sub_process_id;
You seem to pivot your dataset. For this, you can use conditional aggregation:
select col_master_id,
sum(col_semi_id = 1) as col_semi_1_count,
sum(case when col_semi_id = 1 then col_state else 0 end) as col_semi_1_state,
sum(col_semi_id = 2) as col_semi_2_count,
sum(case when col_semi_id = 2 then col_state else 0 end) as col_semi_2_state,
sum(col_semi_id = 3) as col_semi_3_count,
sum(case when col_semi_id = 3 then col_state else 0 end) as col_semi_3_state,
from mytable
group by col_master_id
I don't see how your query relates to your data. This answer is based on your sample data and desired results, not on your query.

Oracle SQL: Update a column from select

I have to update SRCFILE_FULL_COUNT_HIGH. Set new value from NOVA_HODNOTA. Here is working select.
Thank you!
UPDATE SRCFILE_ID, NOVA_HODNOTA, SRCFILE_FULL_COUNT_HIGH as STARA_HODNOTA
from
(
working select:
SELECT /*+ no_index(rh FILEINS_STATUS_FK_I) */
rh.SRCFILE_ID, rh.FILEINS_RECORD_COUNT, rh.FILEINS_EFFECTIVE_DATE, esf.SRCFILE_FULL_COUNT_HIGH,
100*(rh.FILEINS_RECORD_COUNT/esf.SRCFILE_FULL_COUNT_HIGH) as PROCENTA,
CASE
WHEN (100*(rh.FILEINS_RECORD_COUNT/esf.SRCFILE_FULL_COUNT_HIGH)) >= 80
THEN FILEINS_RECORD_COUNT*1.25
ELSE SRCFILE_FULL_COUNT_HIGH
END AS NOVA_HODNOTA
FROM ETL_SOURCE_FILE_INST rh,
(SELECT MAX(FILEINS_EFFECTIVE_DATE) AS maxdate, SRCFILE_ID
FROM ETL_SOURCE_FILE_INST
GROUP BY SRCFILE_ID) maxresults,
ETL_SOURCE_FILES esf
WHERE rh.SRCFILE_ID = maxresults.SRCFILE_ID
and rh.SRCFILE_ID = esf.SRCFILE_ID
AND rh.FILEINS_EFFECTIVE_DATE= maxresults.maxdate
AND RH.FILEINS_INCREMENTAL_FLAG = 'F'
and ESF.SRCFILE_FULL_COUNT_FLAG = 'Y'
and RH.FILEINS_STATUS = 'COMPLETE'
ORDER BY SRCFILE_ID ASC
END of select
)
WHERE STARA_HODNOTA = SRCFILE_FULL_COUNT_HIGH
SET STARA_HODNOTA = NOVA_HODNOTA
;
merge into
ETL_SOURCE_FILE_INST i
using
(
SELECT /*+ no_index(rh FILEINS_STATUS_FK_I) */
rh.SRCFILE_ID, rh.FILEINS_RECORD_COUNT, rh.FILEINS_EFFECTIVE_DATE, esf.SRCFILE_FULL_COUNT_HIGH,
100*(rh.FILEINS_RECORD_COUNT/esf.SRCFILE_FULL_COUNT_HIGH) as PROCENTA,
CASE
WHEN (100*(rh.FILEINS_RECORD_COUNT/esf.SRCFILE_FULL_COUNT_HIGH)) >= 80
THEN FILEINS_RECORD_COUNT*1.25
ELSE SRCFILE_FULL_COUNT_HIGH
END AS NOVA_HODNOTA
FROM ETL_SOURCE_FILE_INST rh,
(SELECT MAX(FILEINS_EFFECTIVE_DATE) AS maxdate, SRCFILE_ID
FROM ETL_SOURCE_FILE_INST
GROUP BY SRCFILE_ID) maxresults,
ETL_SOURCE_FILES esf
WHERE rh.SRCFILE_ID = maxresults.SRCFILE_ID
and rh.SRCFILE_ID = esf.SRCFILE_ID
AND rh.FILEINS_EFFECTIVE_DATE= maxresults.maxdate
AND RH.FILEINS_INCREMENTAL_FLAG = 'F'
and ESF.SRCFILE_FULL_COUNT_FLAG = 'Y'
and RH.FILEINS_STATUS = 'COMPLETE'
) t on (t.SRCFILE_ID = i.SRCFILE_ID)
when matched then
update
set
i.SRCFILE_FULL_COUNT_HIGH = t.NOVA_HODNOTA
where
i.SRCFILE_FULL_COUNT_HIGH = t.SRCFILE_FULL_COUNT_HIGH
;

filter rows based on column values in mysql query

This is my mysql query
SELECT a.model_name,
IF( b.officially_released_year = '".$currentyear."',1,0 ) AS release_year,
IF( b.officially_released_month = '".$first_month."' OR b.officially_released_month = '".$second_month."' OR b.officially_released_month = '".$third_month."' OR b.officially_released_month = '".$currentmonth."' ,1,0) AS release_month
FROM ".TBL_CAR_ADD_MODELS." a, ".TBL_CAR_SPEC_GENERAL." b
WHERE a.model_id = b.model_id AND a.model_status = '1'
ORDER BY a.model_created_on DESC
I want to do one more filtering option in this query. I need to get the records based on release_year = 1 & release_year = 1. I have done release_year and release_month columns through IF STATEMENT in MYSQL QUERY
release_year
IF( b.officially_released_year = '".$currentyear."',1,0 ) AS release_year
release_month
IF( b.officially_released_month = '".$first_month."' OR b.officially_released_month = '".$second_month."' OR b.officially_released_month = '".$third_month."' OR b.officially_released_month = '".$currentmonth."' ,1,0) AS release_month
How do I get the records based on these values (release_month = 1 & release_year = 1) in this query? I have tried WHERE release_month = 1 AND release_year = 1 but this one returns unknown column
You could do this:
SELECT
*
FROM
(
SELECT
a.model_name,
a.model_created_on,
IF( b.officially_released_year = '".$currentyear."',1,0 ) AS release_year,
IF( b.officially_released_month = '".$first_month."' OR b.officially_released_month = '".$second_month."' OR b.officially_released_month = '".$third_month."' OR b.officially_released_month = '".$currentmonth."' ,1,0) AS release_month
FROM ".TBL_CAR_ADD_MODELS." a, ".TBL_CAR_SPEC_GENERAL." b
WHERE a.model_id = b.model_id AND a.model_status = '1'
) AS tbl
WHERE tbl.release_year=1 AND release_month=1
ORDER BY tbl.model_created_on DESC

How to solve this subquery error?

Can you please tell me whats wrong with this?
It throws error
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
And whats meant by using({?SUB_ALLOC_PARM})) I guess its parameter value right?
select distinct LFS_LFS as DN
, LFS_VONNR
, LZL_REFNR
, AGR_TEXT
, LFS_KNR as Store
, LFS_DATOK
, FIL_INDEX as Store_name
, LAN_TEXT as COUNTRY
, LZL_MENGE as Qty
, ANS_NAME1 AS 'Customer Name'
, ANS_NAME2 AS 'Customer Address line 1'
, ANS_STRASSE AS 'Customer Address line 2'
, ANS_STRASSE_2 AS 'Customer Address line 3'
, ANS_ORT AS 'City'
, ANS_TITEL AS 'State'
, LAN_TEXT AS 'Country'
, ANS_PLZ AS 'PostCode'
, ( select FIL_NUMMER
from FUTURA..V_FILIALEN as HO
where HO.FIL_LAND = STORE.FIL_LAND
and HO.FIL_MANDANT = 1
and HO.FIL_ART = 0
) as HO_BRANCH
from FUTURA..V_LIEFHEAD,
FUTURA..V_ARTIKEL,
FUTURA..V_ART_KOPF,
FUTURA..V_LIEFZEIL,
FUTURA..V_LAGER as BR5,
FUTURA..V_FILIALEN as STORE,
FUTURA..V_ANSCHRIF,
FUTURA..V_LAND
where AGR_MANDANT = ART_MANDANT
and AGR_WARENGR = ART_WARENGR
and AGR_ABTEILUNG = ART_ABTEILUNG
and AGR_TYPE = ART_TYPE
and AGR_GRPNUMMER = ART_GRPNUMMER
and LZL_REFNR = ART_REFNUMMER
and ART_MANDANT = LFS_MANDANT
and LFS_LFS = LZL_LFS and LFS_MANDANT = LZL_MANDANT
and LFS_MANDANT = 1
and LZL_REFNR <> 0
and LZL_REFNR = BR5.LAG_REFNUMMER
and LZL_MANDANT = BR5.LAG_MANDANT
and BR5.LAG_MANDANT = 1
and BR5.LAG_FILIALE = LFS_VONNR
and FIL_MANDANT = LZL_MANDANT
and FIL_NUMMER = LFS_KNR
and LAN_MANDANT = FIL_MANDANT
and LAN_NUMMER = FIL_LAND
AND ANS_TYP = 2 -- branches
AND ANS_COUNT = 1 -- sequence 1
AND ANS_MANDANT = FIL_MANDANT
AND ANS_NUMMER = FIL_NUMMER
and LFS_LFS IN (
select distinct PVG_LIEFERSCHEIN
from FUTURA..V_PVERFIL
where PVG_NUMMER IN ({?SUB_ALLOC_PARM})
)
order by
LFS_KNR
Most likely, your
select FIL_NUMMER
from FUTURA..V_FILIALEN as HO
where HO.FIL_LAND = STORE.FIL_LAND
and HO.FIL_MANDANT = 1
and HO.FIL_ART = 0
clause is returning more than one value.

SQL ORDER BY query

I want to have my table,rcarddet, ordered by "SDNO" (not primary key) in ascending order with the exception of "0". So it should turn out to be like:
1
1
2
.
.
10
0
0
My query now is:
SELECT *
FROM `rcarddet`
WHERE `RDATE` = '2011-05-25'
AND `RCNO` = '1'
AND `PLACE` = 'H'
AND `SDNO` != 0
ORDER BY `rcarddet`.`SDNO` ASC;
The easiest way
SELECT * FROM rcarddet
WHERE RDATE = '2011-05-25' and RCNO = '1'and PLACE = 'H'
ORDER BY CASE
WHEN rcarddet.SDNO = 0 THEN [max_number_for_the_type_of_SDNO]
ELSE rcarddet.SDNO
END ASC
SELECT *
FROM `rcarddet`
WHERE `RDATE` = '2011-05-25'
AND `RCNO` = '1'
AND `PLACE` = 'H'
ORDER BY
`SDNO` = 0,
`SDNO`;