Solved

Need help with MySQL Query

Posted on 2013-11-02
3
304 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 200 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now