I am executing the below sql statement but getting the repetition of the record.
Below is the query for the same
select distinct ore.ORDER_RELEASE_GID order_release,
shbuy.SHIPMENT_GID Buy_Shipment,
shsel.SHIPMENT_GID Sell_Shipment,
shbuy.TRANSPORT_MODE_GID Buy_T_Mode,
shbuy.ATTRIBUTE10 Equipment_ID,
shsel.TRANSPORT_MODE_GID Sell_T_Mode,
shbuy.SERVPROV_GID Buy__Carrier,
shsel.SERVPROV_GID Sell__Carrier,
sst1.STOP_NUM Buy_stop_num,
sst2.STOP_NUM Sell_stop_num,
orig.LOCATION_NAME Origin,
orig.CITY Orig_City,
orig.PROVINCE_CODE Orig_State,
orig.POSTAL_CODE Orig_Zip,
dest.LOCATION_NAME Consignee,
dest.CITY Dest_City,
dest.PROVINCE_CODE Dest_State,
dest.POSTAL_CODE Dest_Zip
from ship_unit su, s_ship_unit ssu1, s_ship_unit ssu2, shipment_stop_d ssd1,
shipment_stop ss1, shipment_stop_d ssd2, shipment_stop sst1,
shipment_stop sst2, shipment shbuy, shipment shsel,
order_release ore, location orig, location dest
where su.SHIP_UNIT_GID = ssu1.SHIP_UNIT_GID
and su.SHIP_UNIT_GID = ssu2.SHIP_UNIT_GID
and ssu1.S_SHIP_UNIT_GID = ssd1.S_SHIP_UNIT_GID
and ssu2.S_SHIP_UNIT_GID = ssd2.S_SHIP_UNIT_GID
and ssd1.SHIPMENT_GID = shbuy.SHIPMENT_GID
and ssd2.SHIPMENT_GID = shsel.SHIPMENT_GID
and su.ORDER_RELEASE_GID = ore.ORDER_RELEASE_GID
and shbuy.SHIPMENT_GID = sst1.SHIPMENT_GID
and shsel.SHIPMENT_GID = sst2.SHIPMENT_GID
and ssd1.STOP_NUM = sst1.STOP_NUM
and ssd2.STOP_NUM = sst2.STOP_NUM
and ssd1.STOP_NUM > 1
and ssd2.STOP_NUM > 1
and shbuy.PERSPECTIVE = 'B'
and shsel.PERSPECTIVE = 'S'
-- Common Area
and ss1.LOCATION_GID = orig.LOCATION_GID
and sst1.LOCATION_GID = dest.LOCATION_GID
and shbuy.SHIPMENT_GID = ss1.SHIPMENT_GID
and ss1.STOP_NUM = 1
order by buy_shipment, order_release
The output is as followed
Please let me know what all chnages i need to make in the sql so that it fetches just 1 order release and not twice or thrice as shown in the output.
Thanks
Mrugen
Use rownum for that to filter ore.ORDER_RELEASE_GID and get the lowest buy_stop_num
select distinct ore.ORDER_RELEASE_GID order_release,
shbuy.SHIPMENT_GID Buy_Shipment,
shsel.SHIPMENT_GID Sell_Shipment,
shbuy.TRANSPORT_MODE_GID Buy_T_Mode,
shbuy.ATTRIBUTE10 Equipment_ID,
shsel.TRANSPORT_MODE_GID Sell_T_Mode,
shbuy.SERVPROV_GID Buy__Carrier,
shsel.SERVPROV_GID Sell__Carrier,
sst1.STOP_NUM Buy_stop_num,
sst2.STOP_NUM Sell_stop_num,
orig.LOCATION_NAME Origin,
orig.CITY Orig_City,
orig.PROVINCE_CODE Orig_State,
orig.POSTAL_CODE Orig_Zip,
dest.LOCATION_NAME Consignee,
dest.CITY Dest_City,
dest.PROVINCE_CODE Dest_State,
dest.POSTAL_CODE Dest_Zip
ROW_NUMBER() OVER(partition BY ore.ORDER_RELEASE_GID ORDER BY ore.ORDER_RELEASE_GID, dest.LOCATION_NAME ASC) AS Row
from ship_unit su, s_ship_unit ssu1, s_ship_unit ssu2, shipment_stop_d ssd1,
shipment_stop ss1, shipment_stop_d ssd2, shipment_stop sst1,
shipment_stop sst2, shipment shbuy, shipment shsel,
order_release ore, location orig, location dest
where su.SHIP_UNIT_GID = ssu1.SHIP_UNIT_GID
and su.SHIP_UNIT_GID = ssu2.SHIP_UNIT_GID
and ssu1.S_SHIP_UNIT_GID = ssd1.S_SHIP_UNIT_GID
and ssu2.S_SHIP_UNIT_GID = ssd2.S_SHIP_UNIT_GID
and ssd1.SHIPMENT_GID = shbuy.SHIPMENT_GID
and ssd2.SHIPMENT_GID = shsel.SHIPMENT_GID
and su.ORDER_RELEASE_GID = ore.ORDER_RELEASE_GID
and shbuy.SHIPMENT_GID = sst1.SHIPMENT_GID
and shsel.SHIPMENT_GID = sst2.SHIPMENT_GID
and ssd1.STOP_NUM = sst1.STOP_NUM
and ssd2.STOP_NUM = sst2.STOP_NUM
and ssd1.STOP_NUM > 1
and ssd2.STOP_NUM > 1
and shbuy.PERSPECTIVE = 'B'
and shsel.PERSPECTIVE = 'S'
-- Common Area
and ss1.LOCATION_GID = orig.LOCATION_GID
and sst1.LOCATION_GID = dest.LOCATION_GID
and shbuy.SHIPMENT_GID = ss1.SHIPMENT_GID
and ss1.STOP_NUM = 1
and Row = 1
order by buy_shipment, order_release
Related
The function checks the wavetrend cross and is displayed if the condition is met. I want the function to run for every bar within the last 5 bars. How can I do it with Bar Index
func_wave() =>
n1 = input(10, 'Channel Length')
n2 = input(21, 'Average Length')
obLevel1 = input(60, 'Over Bought Level 1')
obLevel2 = input(53, 'Over Bought Level 2')
osLevel1 = input(-60, 'Over Sold Level 1')
osLevel2 = input(-53, 'Over Sold Level 2')
ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 4)
con = ta.crossover(wt1, wt2)
con
s1 = request.security('BTCUSDT', timeframe.period, func_wave())
s2 = request.security('ETHUSDT', timeframe.period, func_wave())
s3 = request.security('BNBUSDT', timeframe.period, func_wave())
scr_label = 'WT\n'
scr_label := s1 ? scr_label + 'BTCUSDT\n' : scr_label
scr_label := s2 ? scr_label + 'ETHUSDT\n' : scr_label
scr_label := s3 ? scr_label + 'BNBUSDT\n' : scr_label
I = label.new(bar_index -165, 0, scr_label, color=color.green, textcolor=color.white,
style=label.style_label_up, yloc=yloc.price)
label.delete(I[1])
plot(0, color=color.new(color.white, 0))
You could use the ta.barssince function
https://www.tradingview.com/pine-script-reference/v5/#fun_ta{dot}barssince
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.
I have a requirement to get the result from the first matched condition and if it finds result in that level then return from there or go to Next level to
find the result .
Any help appreciated.
This is a prioritization query (with ties). One method uses dense_rank():
select rsc.*
from (select rsc.*,
dense_rank() over (order by case when rsc.entityId = :accountId and rsc.entityTypeCode = 'A' then 1
when rsc.entityId = :companyId and rsc.entityTypeCode = 'C' then 2
when rsc.entityId = :issuerId and rsc.entityTypeCode = 'I' then 3
else 4
end) as seqnum
from CurrentRuleSetContents rsc
where (rsc.entityId = :accountId and rsc.entityTypeCode = 'A') or
(rsc.entityId = :companyId and rsc.entityTypeCode = 'C') or
(rsc.entityId = :issuerId and rsc.entityTypeCode = 'I') or
(rsc.industryCode = :industryCode)
) rsc
where seqnum = 1;
Got this 3 in 1 query:
SELECT * FROM
(
SELECT mesures.date j, AVG(mesures.valeur) maxi
FROM mesures
JOIN plages_horaire ON mesures.id_plage = plages_horaire.id_plage
WHERE MONTH(mesures.date) = '9' AND YEAR(mesures.date) = '2016' AND mesures.code_station = 'P02SE' AND mesures.id_crit = '1' AND mesures.id_type = '1'
GROUP BY mesures.date
) maxi
,
(
SELECT AVG(mesures.valeur) mini
FROM mesures
JOIN plages_horaire ON mesures.id_plage = plages_horaire.id_plage
WHERE MONTH(mesures.date) = '9' AND YEAR(mesures.date) = '2016' AND mesures.code_station = 'P02SE' AND mesures.id_crit = '1' AND mesures.id_type = '2'
GROUP BY mesures.date
) mini
,
(
SELECT AVG(mesures.valeur) moy
FROM mesures
JOIN plages_horaire ON mesures.id_plage = plages_horaire.id_plage
WHERE MONTH(mesures.date) = '9' AND YEAR(mesures.date) = '2016' AND mesures.code_station = 'P02SE' AND mesures.id_crit = '1' AND mesures.id_type = '3'
GROUP BY mesures.date
) moy
GROUP BY j
Problem is that I get what I want excepting values of the 2 last columns are the same at every rows:
query output
I believe it's because of the GROUP BY.
From what I can see from your query, you don't need the plage_horaire table. You can also simplify the logic greatly by using conditional aggregation:
SELECT m.date,
AVG(CASE WHEN m.id_type = 1 THEN m.valeur END) maxi,
AVG(CASE WHEN m.id_type = 2 THEN m.valeur END) mini,
AVG(CASE WHEN m.id_type = 3 THEN m.valeur END) maxmoy,
FROM mesures m
WHERE MONTH(m.date) = 9 AND YEAR(m.date) = 2016 AND
m.code_station = 'P02SE' AND m.id_crit = 1 AND m.id_type IN (1, 2, 3)
GROUP BY m.date ;
Notice that I also removed the quotes from the numeric constants. MONTH() and YEAR() return numbers, so quotes are not appropriate. I am guessing that the ids are numeric as well.
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