Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with MySQL Query

Posted on 2013-11-02
3
Medium Priority
?
336 Views
Last Modified: 2013-11-03
Hello, I need help with a query issue I'm having.... I've added another column within the cw_ship_method table called "ship_method_exempt". The new column has some list values of...

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co

I know i could normalize the table. I did try doing that but that didn't seem to be pulling the right records as well. I would like to try solving it with the list values instead. Just because I would like to learn how to for one reason and the table won't be expanding at all. I know in normal practices normalizing is recommended though. The part I'm not focusing on is here...

AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')

	SELECT
		Min(r.ship_range_from) AS min_range_from,
		Max(r.ship_range_to) AS max_range_to,
		m.ship_method_id,
		m.ship_method_name,
		m.ship_method_rate,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_calctype,
		m.ship_method_archive
	FROM
		(cw_ship_method_countries c
		INNER JOIN cw_ship_methods m
		ON c.ship_method_country_method_id = m.ship_method_id)
		LEFT JOIN cw_ship_ranges r
		ON m.ship_method_id = r.ship_range_method_id
	<!--- if looking up price by range, return only a single range --->
	WHERE 1=1
	<cfif arguments.match_range>
	AND (r.ship_range_from <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">
		AND r.ship_range_to >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
		<cfif arguments.localcalc_only eq true>OR NOT m.ship_method_calctype = 'localcalc'</cfif>
	</cfif>
	AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')
	GROUP BY
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to
	HAVING (
			((Min(r.ship_range_from) <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (Max(r.ship_range_to) >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)
			) 
			<cfif arguments.localcalc_only eq true>OR (NOT m.ship_method_calctype = 'localcalc' AND c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)</cfif>
			)
		<cfif arguments.ship_method_id gt 0>
		AND m.ship_method_id = <cfqueryparam value="#arguments.ship_method_id#" cfsqltype="cf_sql_integer">
		</cfif>
		AND NOT (m.ship_method_archive = 1)
	ORDER BY
		m.ship_method_sort,
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		Min(r.ship_range_from),
		Max(r.ship_range_to)

Open in new window

0
Comment
Question by:brihol44
  • 2
3 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39619124
I don'r really understand your question. Can you explain what is the issue? What you would like to get?

Also if possible please minimize your query just to make a minimal example of what is wrong...
0
 

Author Comment

by:brihol44
ID: 39619149
Hello, I want to filter out shipping methods where session.customer_shipping_category eq either "po, re, co". In the newly created column in shipping methods I have the following values to use for NOT pulling shipping methods that eq true to value of session.customer_shipping_category

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co
0
 
LVL 15

Accepted Solution

by:
gplana earned 800 total points
ID: 39619189
Then I think you want something like this:

SELECT *
FROM session
WHERE customer_shipping_category LIKE '%po%' OR customer_shipping_category LIKE '%re%' OR customer_shipping_categoryLIKE '%co%';

Open in new window


Please try it and let me know if this is what you want.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question